CSS root Selector (:root)

What is CSS :root Selector?

CSS root selector select root element of the document.

Syntax

General syntax of CSS :root selector,

:root {
  property: value;
  property: value;
  ...
}

Example

CSS :root selector select root element of the document.

<!DOCTYPE html>
<html>
<head>
  <title>CSS :root Selector</title>
  <style type="text/css">
    :root {
      background: #ff0000;
    }    
    div {
      width: 400px;
      height: 130px;
      border: 1px solid yellow;
    }
  </style>
</head>
<body>
  <h1>This is a heading</h1>
</body>
</html>

Run it...   »

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 1.5+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 3.1+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.