CSS Selector :root








The :root selector selects the root element in the document. It always returns the html element. The :root is added by CSS3.

Its format is:

:root

Summary

CSS Version

CSS Syntax

:root {
   style properties 
}

Browser compatibility

:root Yes 9.0 Yes Yes Yes




Example

An example showing how to use :root CSS selector.

<!DOCTYPE HTML> 
<html> 
    <head> 
 <!--   ww  w  . j  ava2  s . com-->
        <style type="text/css"> 
        :root { 
            border: thin black solid; 
            padding: 4px; 
        } 
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like HTML.</p> 
    </body> 
</html>

Click to view the demo