CSS: Selector list vs :where() :is()

By Xah Lee. Date: .

in css, is selector list equivalent to :is() or :where()

in css, is selector list equivalent to :is() or :where()

ai answer

No, a CSS selector list is not fully equivalent to either :is() or :where(), though it matches the same elements in simple cases.

Matching behavior

A plain selector list like this:

h1, h2, h3 {
  color: red;
}

selects the same elements as:

:is(h1, h2, h3) { ... }
:where(h1, h2, h3) { ... }

Both :is() and :where() accept a selector list and match any element that matches any of the selectors in that list. This is why they are often used to shorten long, repetitive selector lists (especially when combined with combinators).

Key differences

  1. Specificity

    • In a plain selector list (h1, h2, h3), each selector keeps its own specificity. The rule is effectively treated as separate rules.
    • :is() takes the specificity of the most specific selector in its argument list.
    • :where() always has zero specificity.
  2. Forgiving parsing

    • A normal selector list is unforgiving: if any selector in the list is invalid, the entire rule is dropped.
    • :is() and :where() use a forgiving selector list: invalid/unsupported selectors are ignored, and the rest still apply.
  3. Where they can be used

    • A plain comma-separated list only works at the top level of a selector (or in certain list contexts).
    • :is() / :where() can appear in the middle or end of a more complex selector, e.g. article :is(h1, h2) > span.

Summary

So they are convenient alternatives for writing the same matching logic more compactly (especially in complex selectors), but they are not drop-in equivalents due to specificity and error-handling differences.