CSS :root Selector
Example
:root {
background: red;
color: white;
}
Meaning
The :root selector selects the root element of a tree representing the document.
In HTML, :root represents the <html> element and is identical to the selector html, except that its specificity is higher.
Version: CSS3
Standard Syntax
:root {
css declarations;
}
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Status
More Example
Example
:root {
--bg-color: red;
--main-color: green;
}
h1 {
background: var(--bg-color);
}
p {
color: var(--main-color);
}