1. Web
  2. CSS
  3. :root

Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

:root

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨Juli 2015⁩.

Die :root CSS Pseudoklasse entspricht dem Wurzelelement eines Baumes, der das Dokument repräsentiert. In HTML steht :root für 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

Siehe auch

Help improve MDN

Learn how to contribute Diese Seite wurde automatisch aus dem Englischen übersetzt.

AltStyle によって変換されたページ (->オリジナル) /