CSS: :where selector (is any of)

By Xah Lee. Date: .

Selector :where

:where(s1, s2, etc)

match any of the selectors s1, s2 etc.

s can be simple selector, compound selector or complex selector.

.nav a {
 color: red;
}

/* 0 priority. does not override others */
:where(a) {
 color: blue;
}

Example

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;
}

Specificity

:where() has zero specificity (0,0,0).

Difference between :is() vs :where()

Browser support

the selectors :is() and :where() are supported by all major browsers since 2022.

CSS Selector. pseudo-class functions

CSS. Selectors

Selector types
Simple selectors
Combinators
Selector list
Nesting syntax
Special selector
Misc