: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.
:root
は CSS の擬似クラスで、文書を表すツリーのルート要素を選択します。 HTML では :root
は <html>
要素を表し、詳細度が高いことを除けば html
セレクターと同等です。
css
/* 文書のルート要素(HTML の場合は <html>)を選択 */
:root {
background: yellow;
}
構文
:root
例
グローバルの CSS 変数
:root
はグローバルの CSS 変数を宣言するのに便利です。
css
:root {
--main-color: hotpink;
--pane-padding: 5px 42px;
}
仕様書
Specification |
---|
Selectors Level 4 # root-pseudo |
ブラウザーの互換性
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.