Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. [CSS Selector] E:root

[CSS Selector] E:root

':root' selects the root element of the HTML document. This is equivalent to using the 'html' selector, but ':root' has higher specificity (priority). Note that it does not work in IE8 and below.

A use case for ':root' is when you want to simply increase CSS specificity without using '!important'. So when you run into specificity issues, adding ':root ' at the beginning of a selector may solve the problem.

Sample Code

:root { background-color: yellow;} /* ':root' has higher specificity, so the background becomes yellow. */
html { background-color: blue;} /* ':root' has higher specificity, so this declaration is not applied. */
:root p { color: red;} /* To raise specificity without using '!important', write it this way. */
p { color: blue;} /* ':root p' has higher specificity, so this declaration is not applied. */

Browser Display Result

:root { background-color: yellow;} /* ':root' has higher specificity, so the background becomes yellow. */
html { background-color: blue;} /* ':root' has higher specificity, so this declaration is not applied. */
:root p { color: red;} /* To raise specificity without using '!important', write it this way. */
p { color: blue;} /* ':root p' has higher specificity, so this declaration is not applied. */

<p>This is a p element.</p>

Browser Compatibility

Chrome Chrome
1+
Firefox Firefox
1+
Safari Safari
1+
Edge Edge
12+
Supported in all versions
IE IE
11
10
9
8 ×
7 ×
6 ×
Opera Opera
9.5+
8 and earlier ×
iOS Safari iOS Safari
1+
Android Android Browser
37+
36 and earlier ×
Chrome Android Chrome Android
Latest
Same support as desktop
Firefox Android Firefox Android
Latest
Same support as desktop

※ Version data is based on MDN.

If you find any errors or copyright issues, please .