:where()
Example
ul[class],
ol[class] {
list-style: none;
padding: 0;
}:where(ul, ol)[class] {
list-style: none;
padding: 0;
}Only the [class] part counts now, so a single class can override this reset without extra specificity.
Common mistakes
- Wrapping component styles in
:where()and then losing to a plain element rule. - Thinking
:where()changes which elements match, while it only changes specificity.
Key points
- Resets and library defaults are wrapped in
:where()so any user selector overrides them. - Code does not use
:where()where styles must win over others, since it adds no specificity.
Interview questions
What is the specificity of :where()?
Always zero. Nothing inside :where() counts, though selectors outside it still do.
Should I use :where() or @layer for low-priority styles?
Both work. :where() lowers one selector's specificity, while @layer lowers a whole group of rules at once.