Menu

1 / 2

The Different Ways to Select <html> in CSS | CSS-Tricks

CSS-Tricks·Daniel Schwarz·8 months ago
#ZQKnpt
#selectors#root#scope#element#matches
Reading 0:00
15s threshold

Temani Afif recently did this exercise and I thought I’d build off of it. Some of these are useful. Many of them are not. There’s a bird at the end!

html

html { /* I mean, duh */ }

:root

:root { /* Sarsaparilla, anyone? */ }

:root is a CSS pseudo-class that matches the root element of the current (XML) document. If the current document is a HTML document, then it matches <html> . The XML documents that you’ll most likely encounter as a web developer (besides HTML) are:

SVG documents: :root matches <svg>

RSS documents: :root matches <rss>

Atom documents: :root matches <feed>

MathML documents: :root matches <math>

Other XML documents: :root matches the outermost element (e.g., <note> )

But what’s the practicality of :root ?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.