Sub topic 14
Browser support and legacy names
This chapter covers which browsers support :is() and :where(), what the older prefixed names were, and how to ship these selectors safely. It assumes you can already write :is() and :where() selectors, know how selector lists are dropped when one item is invalid, and understand specificity. The specificity and forgiving-parsing chapters cover that material.
Where support stands
:is() and :where() shipped in all major engines between mid-2020 and early 2021. They are now in every current release of Chrome, Edge, Firefox, and Safari.
| Engine | First version with `:is()` and `:where()` | Approximate date |
|---|---|---|
| Firefox | 78 | June 2020 |
| Safari | 14 | September 2020 |
| Chrome and Edge | 88 | January 2021 |
The version numbers are the ones to remember. Check a compatibility table such as MDN's browser compatibility data or Can I use before relying on exact dates, because those tables are updated as engines change.
For most projects the practical question is whether your supported-browser list reaches back before 2021. If it does not, you can use both pseudo-classes directly. If it does, you need a plan for the browsers that lack them.
What older browsers do with an unknown selector
Old engines do not understand :is(). They treat it as an unknown pseudo-class, which makes the selector invalid. As covered in the forgiving-parsing chapter, an invalid selector in an ordinary selector list invalidates the whole rule.
/* In a browser without :is(), the entire rule is discarded */
article :is(h1, h2, h3) a {
text-decoration: underline;
}Nothing breaks loudly. The declarations are silently skipped, and the page falls back to whatever the browser's defaults and your other rules provide. That is the failure mode to design around.
Legacy names
Before the standard name existed, engines shipped their own versions of the same idea.
| Name | Engines | Notes |
|---|---|---|
| `:-webkit-any()` | Chrome (from version 12) and Safari (from version 5) | Prefixed, vendor-specific |
| `:-moz-any()` | Firefox (from version 4) | Prefixed, vendor-specific |
| `:matches()` | Safari 9 to 13 | An early unprefixed name from the specification draft |
| `:is()` | All current engines | The standard name |
The specification renamed :matches() to :is(), so :matches() is not part of the final standard. Do not write it in new code. Current browsers do not treat it as a general alias for :is().
The prefixed forms are similar to :is() but not identical. Early implementations were more limited:
- They often accepted only simple or compound selectors in the list, with no combinators.
- They did not use forgiving parsing, so one invalid item invalidated the rule.
- Their specificity handling was not guaranteed to match the standard.
- A single prefixed name is understood by only one engine family, so each one needs its own rule.
There is also no legacy equivalent of :where(). It was introduced later, with its zero-specificity behavior, and no engine shipped a prefixed version of it. Nothing in the old syntax can reproduce what :where() does.
Why you cannot put legacy names in one list
It is tempting to write all the names in a single selector list so that every browser finds one it understands. That does not work:
/* Wrong: engines that do not know one item drop the whole rule */
article :-webkit-any(h1, h2, h3) a,
article :-moz-any(h1, h2, h3) a,
article :is(h1, h2, h3) a {
text-decoration: underline;
}Each browser understands at most one of these three items and treats the other two as unknown. Because the outer list is not forgiving, the unknown item invalidates the entire rule, so it applies nowhere. Forgiving parsing only helps inside the argument list of :is() and :where(), not at the top level.
The fix is to give each name its own rule:
article :-webkit-any(h1, h2, h3) a {
text-decoration: underline;
}
article :-moz-any(h1, h2, h3) a {
text-decoration: underline;
}
article :is(h1, h2, h3) a {
text-decoration: underline;
}Each browser drops the rules it does not understand and applies the one it does. This works only because the three rules carry identical declarations. If they differed, the order and specificity of whichever rule survives would decide the outcome.
This is verbose, and it is the reason most projects stop writing prefixed forms once their support window moves past 2021.
Feature detection with @supports
Rather than guessing from browser versions, you can ask the browser directly. The @supports selector() condition tests whether a selector parses.
/* Baseline that works everywhere */
article h1 a,
article h2 a,
article h3 a {
text-decoration: underline;
}
/* Enhancement only for browsers that understand :is() */
@supports selector(:is(a)) {
article :is(h1, h2, h3) a {
text-decoration: underline;
text-underline-offset: 0.2em;
}
}The baseline rule gives every browser a working result. The block inside @supports applies only when :is() is understood. Here the enhancement adds a property the baseline lacks. If the declarations were identical, the second rule would add nothing and you would have kept the repetition you were trying to remove.
Use :where() in the test when your enhancement depends on it:
@supports selector(:where(a)) {
:where(ul, ol) {
margin: 0;
padding-left: 1.5rem;
}
}There are two gaps in this approach:
@supports selector()itself needs support. It arrived in Chrome 83, Firefox 69, and Safari 14.1. A browser that predates it ignores the whole@supportsblock, which is the safe outcome.- Safari 14.0 understands
:is()but not@supports selector(). It skips the guarded block even though it could have applied it. If that version matters to you, put the baseline rule where it covers it.
Choosing a strategy
The options in the lower branches are worth comparing:
- Use the pseudo-classes directly. This is the simplest and correct choice when your support list starts at the versions in the table above.
- Write a baseline plus a guarded block. The baseline is plain, repetitive CSS. The
@supportsblock holds the compact version. You maintain two copies, so use this only for the parts that matter. - Expand at build time. A build tool takes your
:is()selectors and writes out the long form for older browsers. PostCSS Preset Env includes a plugin for this. The output is correct for matching but can grow large, because nested lists multiply. - Use cascade layers instead of
:where(). If your goal is overridable defaults, a lower layer gives the same low priority without the pseudo-class. Layers need their own support, which also dates from 2022 in the major engines, so they do not help with older browsers.
Why build-time expansion cannot fully replace :where()
A tool can rewrite :is(h1, h2, h3) a as three separate selectors, and the matched elements stay the same. Specificity also stays close, though not exact. Per the specificity chapter, :is() takes the specificity of its most specific argument, while the expanded form gives each selector its own specificity. The expansion can therefore be lower than the original for the weaker alternatives.
:where() has no such rewrite. Its defining feature is that it contributes no specificity, and a plain selector cannot have its specificity reduced. A tool could emit the expanded selectors, but they would carry full specificity. Defaults that were meant to be overridden by a single class would then win instead. When you rely on :where() for low-priority defaults, treat older browsers as getting a different cascade, and test that behavior deliberately.
Checking your own stylesheet
When you inherit a stylesheet or audit a library, look for these signs:
:-webkit-any(or:-moz-any(in the source, which usually marks a prefixed workaround that can be replaced if your support window allows.:matches(in the source, which is outdated and not part of the standard.- Several near-identical rules that differ only in the pseudo-class name, which is the pattern from the earlier section.
- A selector list at the top level that mixes
:is()with names an old browser would not know.
A quick search finds all of them:
grep -rnE ":-webkit-any\(|:-moz-any\(|:matches\(" src/Replace each hit with :is() only after confirming that your supported browsers all handle it, and keep any fallback rules that are still needed.
Exercise
Your support window includes Chrome 85. You write main :is(h2, h3) a { color: teal; } with no fallback. What happens in Chrome 85, and how would you fix it so links still get a color?
Show answer
Chrome 85 does not understand :is(), so the selector is invalid and the browser discards the whole rule. The links keep their default color. To fix it, add a baseline rule written the long way, main h2 a, main h3 a { color: teal; }, which every browser understands. You can then keep the :is() version inside @supports selector(:is(a)) if it adds something the baseline lacks.
Exercise
A colleague writes one rule with the selector list section :-webkit-any(p, li), section :-moz-any(p, li), section :is(p, li). Explain why it fails in Firefox 70 and what to do instead.
Show answer
Firefox 70 understands only :-moz-any(). It treats :-webkit-any() and :is() as unknown pseudo-classes, and a top-level selector list is not forgiving, so the whole rule is invalid and nothing matches. Split it into three separate rules, one per name, each with the same declarations. Each browser then drops the rules it does not understand and applies the one it does.
Exercise
Why is there no legacy fallback for :where(), and what is the closest substitute for low-priority defaults in a browser that supports cascade layers?
Show answer
No engine ever shipped a prefixed or early form of :where(), so older browsers have nothing equivalent to use. Rewriting it as plain selectors produces full specificity, which defeats its purpose. A rule placed in a lower-priority cascade layer is the closest substitute, because later layers and unlayered rules override it regardless of selector specificity.