DEV Community

Discussion on: What are CSS variables?

alohci profile image
Nicholas Stimpson

One thing I find quite quirky is the way everybody uses :root for their "all" selector with CSS variables rather than html . Unless you're using CSS with an XML document (which is pretty rare) all you're achieving is using an unnecessarily high specificity selector. Something that as a general practice is best avoided.

The only reason I can think of for doing that is that's what the specification does, and it does it because it doesn't then have to distinguish between use with HTML and XML documents. And everyone is just then copying from everyone else.

jennakoslowski profile image
JennaKoslowski Author

I learned it as both ways but no one ever really explained the difference. So I learned something new! Thank you!