Codectionary / Developer documentation / CSS

:is() and :where()

:is() and :where() both accept a list of selectors and match any of them, letting you write more compact selector groups. The key difference is specificity: :is() takes on the specificity of its most specific argument, while :where() always contributes zero specificity, making its rules trivially easy to override.

Syntax

:is(selector-list)
:where(selector-list)

Examples

Reducing Repetition with :is()

Combining what would otherwise be several separate selectors.

/* Without :is() */
header a:hover, main a:hover, footer a:hover { color: blue; }

/* With :is() - equivalent, more concise */
:is(header, main, footer) a:hover { color: blue; }

The Specificity Difference

Why :where() is preferred for low-priority base styles.

/* :is() takes on the highest specificity among its arguments */
:is(#sidebar, .content) p { color: gray; } /* behaves like #sidebar specificity */

/* :where() always contributes ZERO specificity - trivially overridable */
:where(#sidebar, .content) p { color: gray; } /* easy for any other rule to override */

Parameters and values

  • :is() (pseudo-class): Matches any selector in the list, uses highest specificity among them
  • :where() (pseudo-class): Matches any selector in the list, always contributes zero specificity

Best practices

  • Use :is() to shorten repetitive selector lists that share a common descendant pattern
  • Use :where() specifically for reset styles, base component styles, or CSS you expect (and want) other rules to easily override
  • Remember :where() zero-specificity is a genuine tool for library/design-system authors, so consumers can override defaults without fighting specificity
  • Both accept complex selector lists, including combinators, giving significant power in a compact syntax

At a glance

Purpose
Presentation and layout
File extension
.css
Runs in
Web browsers
Usually used with
HTML and JavaScript

Specifications & further reading

Related CSS documentation