:root
Quick Summary for :root
The
:root
CSS pseudo-class matches the root element of a tree representing the document. In HTML, :root
represents the <html>
element and is identical to the selector html
, except that its specificity is higher.
Code Usage for :root
/* Selects the root element of the document: <html> in the case of HTML */ :root { background: yellow; }
More Details for :root
:root
The :root
CSS pseudo-class matches the root element of a tree representing the document. In HTML, :root
represents the <html>
element and is identical to the selector html
, except that its specificity is higher.
/* Selects the root element of the document: <html> in the case of HTML */ :root { background: yellow; }
Syntax
:root
Examples
Declaring global CSS variables
:root
can be useful for declaring global CSS variables:
:root { --main-color: hotpink; --pane-padding: 5px 42px; }
Specifications
Specification |
---|
Selectors Level 4 # root-pseudo |
See also
<html>
Document.rootElement
Node.getRootNode()
Element.shadowRoot
ShadowRoot
Last modified: Aug 12, 2021, by MDN contributors
Select your preferred language English (US)DeutschEspañolFrançais日本語한국어PolskiPortuguês (do Brasil)Русский中文 (简体) Change language Posted in
12:22 am, February 22, 2022
Add Comment
Other Items in CSS
rgb()
rgba()
:right
right
@right-bottom
:root
rotate
rotate()
rotate3d()
rotateX()
rotateY()
rotateZ()
row-gap
ruby-align
ruby-position
saturate()
scale
scale()
scale3d()
scaleX()
scaleY()
scaleZ()
:scope
scroll-behavior
scroll-margin
scroll-margin-block
scroll-margin-block-end
scroll-margin-block-start
scroll-margin-bottom
scroll-margin-inline
scroll-margin-inline-end
scroll-margin-inline-start
scroll-margin-left
scroll-margin-right
scroll-margin-top
scroll-padding
scroll-padding-block
scroll-padding-block-end
scroll-padding-block-start
scroll-padding-bottom
scroll-padding-inline
scroll-padding-inline-end
scroll-padding-inline-start
scroll-padding-left
scroll-padding-right
scroll-padding-top
scroll-snap-align
scroll-snap-stop
scroll-snap-type
@scroll-timeline