CKTIS / CSS
:root — the document root element
The :root pseudo-class selects the document’s root element. In an ordinary HTML document, that element is html, not body.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
:root { /* declarations */ }:root is a structural pseudo-class that selects the document’s root element. It takes no arguments: write :root, not :root(). In an ordinary HTML document, it matches html, not body. In other document languages, the root element can have a different name.
The specificity of :root is (0,1,0), while the type selector html has (0,0,1). These are different selectors even when they target the same element. In the example, the :root rule gives html a green border; it does not select every element in the document.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>:root demo</title>
<style>
:root { border: 4px solid green; }
</style>
</head>
<body>
<p>Root demo</p>
</body>
</html>Result
Root demo The html element has a 4px solid green border.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.