CSS: :where selector (is any of)
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()
- specificity of
:is()is the highest specificity of the selectors inside it. - specificity of
:where()is 0.
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
- CSS: type selector (tag name)
- CSS: universal selector (* any tag)
- CSS: class selector (.x)
- CSS: ID selector (#)
- CSS: attribute selector ([x])
Combinators
- CSS: descendant selector (space)
- CSS: child selector (>)
- CSS: adjacent sibling selector (+)
- CSS: subsequent sibling selector (~)
Selector list
Nesting syntax
Special selector
- CSS: :root selector
- CSS: no child selector
- CSS: first child, last child, only child selectors
- CSS: nth-child selector
- CSS: nth-child arg of selector
- CSS: nth-of-type selector
- CSS: pseudo-class selector (:)
- CSS: pseudo-element selector (::)
- CSS: negation selector (:not)
- CSS: :has descendant selector