X

Headline

This is an important message requiring you to make a choice if you're based in the EU.

CSS :root Pseudo Class

The :root pseudo-class selects the element that represents the root of the document.

In HTML, the root element is always the <html> element.

In SVG and XML, the :root pseudo-class can refer to a higher-level ancestor.

Version

CSS3

Syntax

:root {
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <style>
      :root {
      background-color: #8ebf42;
      padding: 2em;
      }
      body {
      background-color: #eee;
      padding: 1.5em;
      }
    </style>
  </head>
  <body>
    <h2>:root selector example</h2>
    <p>Lorem ipsum is simply dummy text</p>
  </body>
</html>

Browser support

4.0+ 12.0+ 3.5+ 3.2+ 10.0+

Practice Your Knowledge

Which statement is correct about CSS :root pseudo class?



Do you find this helpful?

Related articles