Widely availableSupported across all major browsers. Safe to use in production.

Overview

The :root pseudo-class matches the root element of the document, usually the <html> element.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
1
18
1
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

CSS
:root {
  --color-primary: #3498db;
  --spacing-md: 16px;
  --font-base: 1rem;
}

Live demo

CSSvariable. definition

CSS CSSvariable. definition demo.

PreviewFullscreen

spe-shingvariable

CSS spe-shingvariable demo.

PreviewFullscreen

fontsizevariable

CSS fontsizevariable demo.

PreviewFullscreen

Use cases

  • Using :root

    The :root pseudo-class matches the root element of the document, usually the <html> element.

Cautions

  • May not be supported in older browsers.

Accessibility

  • Make sure visual changes are conveyed appropriately to assistive technology.

Powered by web-features