:root
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Die :root
CSS Pseudo-Klasse stimmt mit dem Wurzelelement eines Baums überein, der das Dokument repräsentiert. In HTML repräsentiert :root
das <html>
-Element und ist identisch mit dem Selektor html
, außer dass seine Spezifität höher ist.
css
/* Selects the root element of the document:
<html> in the case of HTML */
:root {
background: yellow;
}
Syntax
css
:root {
/* ... */
}
Beispiele
Globale CSS-Variablen deklarieren
:root
kann nützlich sein, um globale CSS-Variablen zu deklarieren:
css
:root {
--main-color: hotpink;
--pane-padding: 5px 42px;
}
Spezifikationen
Specification |
---|
Selectors Level 4 # root-pseudo |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
:root |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.