:root
The :root CSS pseudo-class matches 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 (0-1-0) is higher than html's (0-0-1).
css
/* Selects the root element of the document: <html> in the case of HTML */ :root { background: yellow; }
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 1 | 12 | 1 | 1 | 18 | 1 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
CSS
:root {
--color-primary: #3498db;
--spacing-md: 16px;
--font-base: 1rem;
} Live demo
Use cases
-
Using :root
The :root CSS pseudo-class matches the root element of a tree representing the document.
Cautions
- May not be supported in older browsers.
Accessibility
- Make sure visual changes are conveyed appropriately to assistive technology.