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:



CSS Version

CSS Syntax

:root {
   style properties 

Browser compatibility

:root Yes 9.0 Yes Yes Yes


An example showing how to use :root CSS selector.

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

Click to view the demo