CSS Selector: is any of (is, where)
the selectors :is() and :where() are supported by all major browsers since 2022.
:is() — select any of
:is(s1, s2, etc)-
lets you group selectors. It matches an element if any of the selectors s1, s2 etc match.
meaning is basically the same as just
s1, s2, etc:is(h1, h2, h3, h4, h5, h6) { color: red; } /* above is same as the following */ h1, h2, h3, h4, h5, h6 { color: red; } note:
:is()was named:matches()
Example 2: Complex combinations
/* Style links that are either in nav or are buttons */ :is(nav a, button.link, .card a) { color: royalblue; text-decoration: underline; }
Specificity
:is() takes the highest specificity of the selectors inside it.
:is(#header, .nav) a { } /* specificity = 0,1,0 (from #header) */
:where() — select any of, but 0 specificity
:where(s1, s2, etc)-
same as the
:isbut contributes zero specificity (0,0,0).This is very useful for writing non-intrusive base styles that are easy to override.
/* These won't block more specific rules */ :where(a) { color: blue; } /* This will override the :where() rule easily */ .nav a { color: red; }
Real-world use case: Component libraries
/* Library styles */ :where(.button) { padding: 0.75rem 1.5rem; border-radius: 9999px; } /* User can easily override */ .my-custom-button { padding: 1rem 2rem; /* overrides without fighting specificity */ }
Key Difference Summary:
| Feature | :is() |
:where() |
|---|---|---|
| Specificity | Highest inside list | Always 0,0,0 |
| Use case | Grouping + power | Non-intrusive base styles |
| Override difficulty | Higher | Very easy |
Practical Combined Examples
/* Zero-specificity headings in articles */ article :where(h1, h2, h3, h4) { scroll-margin-top: 5rem; }
/* Complex card variations */ .card:is(:has(img), :has(video)) { display: grid; grid-template-columns: 1fr 2fr; }
Tips & Best Practices
- Specificity: Prefer
:where()for utility/base layers. - Chaining: You can combine them:
article:has(:is(h2, h3)) :where(p) { ... }
example
.card { border: solid 1px grey; } .card:has(img) { border: solid 1px red; } .card:where(:has(h3)) { border: solid 1px pink; }
CSS, Selectors
- CSS Selector: Index
- CSS Selector: Tutorial
- CSS Selector: check tag name
- CSS Selector: check attribute
- CSS Selector: root element
- CSS Selector: check parent
- CSS Selector: no child
- CSS Selector: check descendant (has)
- CSS Selector: check sibling
- CSS Selector: pseudo-class
- CSS Selector: pseudo-element
- CSS Selector: negation (not)
- CSS Selector: is any of (is, where)
- CSS Selector: syntax shortcuts
- CSS Selector: Simple, Compound, Combinator, Complex
- CSS Selector: pseudo-class functions