--- title: ':root' slug: 'Web/CSS/:root' tags: - CSS - CSS 伪类 translation_of: 'Web/CSS/:root' ---
:root 这个 CSS 伪类匹配文档树的根元素。对于 HTML 来说,:root 表示 {{HTMLElement("html")}} 元素,除了优先级更高之外,与 html 选择器相同。
在声明全局 CSS 变量时 :root 会很有用:
:root {
--main-color: hotpink;
--pane-padding: 5px 42px;
}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('CSS4 Selectors', '#root-pseudo', ':root')}} | {{Spec2('CSS4 Selectors')}} | No change |
| {{SpecName('CSS3 Selectors', '#root-pseudo', ':root')}} | {{Spec2('CSS3 Selectors')}} | Initial definition |