CSS Reference ยท Pseudo-classes
The :where() pseudo-class
Reference for the CSS :where() pseudo-class: group selectors like :is() but with zero specificity, ideal for resets, defaults and easy-to-override library styles.
The :where() pseudo-class works like :is(): it matches an element that matches any selector in its list. The difference is that :where() always contributes zero specificity, no matter what is inside it.
That makes it the best tool for defaults that must be easy to override: resets, base styles and library styles. Anyone who writes a simple .btn rule later will win without needing !important.
:where(ul, ol) { padding-left: 1.25rem; }
Try it
The first box uses the :where() default. The second shows a plain .highlight rule overriding it with no extra effort.
Syntax
:where( <forgiving-selector-list> ) { }
- Arguments: a comma-separated list of selectors (complex selectors allowed). Invalid entries are ignored.
- Specificity: always (0, 0, 0). Selectors outside the pseudo-class still count normally.
Values
| Syntax and arguments | Description |
|---|---|
:where(a, b) |
Matches a or b with no specificity. |
:where(.x) p |
The .x adds nothing, so the whole selector counts as p (0, 0, 1). |
a:where(:hover, :focus) |
The a type counts (0, 0, 1); the states add 0. |
:where() |
An empty list matches nothing. |
Usage notes
- Build overridable defaults.
:where(.btn) { ... }can be restyled by any later class selector regardless of source order inside the same layer. - Resets.
:where(h1, h2, h3, h4, h5, h6) { margin: 0 }resets headings without causing specificity wars. - Be careful with conflicts. Because the rule is so weak, an unrelated element selector like
a { color: blue }may override your:where()rule. Zero specificity is not "lowest priority" magic; it just ties with, or loses to, everything else. - Cascade layers. In a layered architecture,
@layeralready controls priority.:where()complements it by keeping specificity low inside a layer. - Forgiving parsing works the same as in
:is(), so a mistyped entry is silently dropped. - Pseudo-elements are not allowed in the list.
Browser support
Baseline since 2021 (Chrome and Edge 88, Firefox 78, Safari 14).
Related
:is()โ same matching, highest-argument specificity:not()@layer- Lesson: Selector Functions
- Lesson: Specificity