CSS :root
의사 클래스는 문서 트리의 루트 요소를 선택합니다 HTML의 루트 요소는 <html>
요소이므로, :root
의 명시도가 더 낮다는 점을 제외하면 html
선택자와 똑같습니다.
/* 문서의 루트 요소 선택
HTML에서는 <html> */
:root {
background: yellow;
}
구문
:root
예제
전역 CSS 변수 선언하기
:root
는 전역 CSS 변수 선언에 유용하게 사용할 수 있습니다.
:root {
--main-color: hotpink;
--pane-padding: 5px 42px;
}
명세
Specification | Status | Comment |
---|---|---|
Selectors Level 4 The definition of ':root' in that specification. |
Working Draft | No change. |
Selectors Level 3 The definition of ':root' in that specification. |
Recommendation | Initial definition. |
브라우저 호환성
BCD tables only load in the browser
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.