CSS Reference ยท Pseudo-classes
The :is() pseudo-class
Reference for the CSS :is() pseudo-class: match any selector in a list, shorten repetitive rules, and understand its specificity and forgiving parsing.
The :is() pseudo-class takes a list of selectors and matches an element if it matches any one of them. Its main job is to shorten repetitive selectors. Instead of writing header a, nav a, footer a, you write :is(header, nav, footer) a.
Two details matter: the list is forgiving (an invalid selector in it is ignored rather than breaking the rule), and the specificity of :is() equals that of its most specific argument.
:is(h1, h2, h3) > a { text-decoration: none; }
Try it
Links in header, nav and footer are pills; the link in main keeps its own colour.
Syntax
:is( <forgiving-selector-list> ) { }
- Arguments: a comma-separated list of selectors, including complex ones.
- Specificity: equal to the most specific selector in the list, even if the element matched a less specific one.
- Pseudo-elements are not allowed inside
:is().
Values
| Syntax and arguments | Description |
|---|---|
:is(a, b) |
Matches elements that match a or b. |
:is(.x, #y) p |
Used as a parent in a longer selector. |
p:is(:hover, :focus-visible) |
Combines states without repeating the whole selector. |
:is() |
An empty list matches nothing. |
Usage notes
- Specificity is the highest argument.
:is(.a, #b)counts as an ID (1, 0, 0) even when the element only matches.a. If you need the list to add no weight, use:where(). - Forgiving parsing.
:is(.ok, ::-nonsense-pseudo)still works for.ok. This helps when mixing vendor-specific selectors, but it can also hide typos. - Nesting multiplies.
:is(a, b) :is(c, d)replaces four separate selectors, and the saving grows fast with larger lists. - Matches the element itself.
div:is(.a, .b)is adivthat has either class.div :is(.a, .b)is any.aor.binside adiv. Mind the space. - CSS nesting. In nested rules,
&is wrapped with the same behaviour as:is()around the parent selector list. - Inside
:has()and:not(). You can nest them to build compact conditions.
Browser support
Baseline since 2021 (Chrome and Edge 88, Firefox 78, Safari 14). Older code used :matches() or :-webkit-any(), which you can now drop.
Related
:where()โ the same, with zero specificity:not()โ negation:has()โ relational selector- Lesson: Selector Functions
- Lesson: Specificity