Sub topic 3
Fallbacks you already get from the cascade
This chapter assumes you know basic CSS syntax and how source order resolves conflicts between declarations. Before reaching for @supports, you should know that the cascade already provides a fallback mechanism. Many enhancements need nothing more than two declarations in the right order.
How browsers handle declarations they don't understand
When a browser parses a stylesheet, it checks each declaration. If the property is unknown, or the value is not valid for that property, the browser drops that one declaration. It keeps parsing the rest of the rule and the rest of the stylesheet. No error is shown to the user.
This is called error recovery, and it is what makes the pattern work. If two declarations for the same property appear in one rule, the later one wins when the browser accepts both. If the browser rejects the later one, the earlier one is still there.
.card {
width: 300px;
width: min(100%, 300px);
}A browser that supports min() reads both lines, and the second wins. A browser that cannot parse min() throws the second line away and uses 300px.
The ordering rule
Put the fallback first and the enhancement second. If you reverse them, a modern browser still ends up with the fallback, because the later declaration wins. The enhancement is then wasted.
.link {
color: #0a7a4b;
color: oklch(0.55 0.13 160);
}Older browsers keep the hex color. Browsers that understand oklch() use it.
What the cascade can and cannot do
This technique works only when the browser fails at parse time. It has limits:
- It works for a new value on an existing property, such as
min(),oklch()orclamp(). - It works for a new property whose old equivalent you can set beforehand.
- It does not work when a browser accepts a value but renders it poorly. The declaration is valid, so no fallback happens.
- It cannot switch several related declarations at once. Changing
displaytogridalso means changing the child rules, and a single duplicated line cannot do that.
For that last case you need @supports, which the next chapter covers.
The var() exception
Custom properties break the pattern. A declaration that uses var() is always accepted at parse time, because the browser cannot know yet whether the final value is valid. If the value turns out to be invalid, the declaration is "invalid at computed-value time". The browser does not fall back to the earlier declaration. It uses the property's inherited or initial value instead.
:root {
--max: min(100%, 300px);
}
.card {
width: 300px;
width: var(--max);
}In a browser without min(), --max holds a value that width cannot use. The width: var(--max) declaration still wins the cascade, and width becomes auto. The 300px fallback is ignored. If you use custom properties to carry new syntax, wrap the enhancement in @supports instead.
Common mistakes
| Mistake | Result | Fix |
|---|---|---|
| Enhancement written before the fallback | The fallback overrides the enhancement everywhere | Write the fallback first |
| Fallback and enhancement in different rules with different specificity | The higher-specificity rule wins regardless of order | Keep both declarations in the same rule |
| New syntax inside `var()` | The fallback never applies | Use `@supports` |
| Enhancement is valid but looks wrong in the old browser | No fallback is triggered | Test the layout, or gate it with `@supports` |
A practical check
You can confirm a declaration was dropped without an old browser. In browser developer tools, an invalid declaration appears struck through in the Styles panel, often with a warning icon. A declaration that parsed but lost the cascade is also struck through, but it has no warning icon. Check both cases when a fallback seems not to work.
Exercise
A stylesheet has .box { width: min(100%, 20rem); width: 20rem; }. In a browser that supports min(), which width applies, and what should change so the min() value is used?
Show answer
The width is 20rem, because the later declaration wins when both parse. Swap the order so width: 20rem; comes first and width: min(100%, 20rem); comes second. A browser without min() then drops the second line and keeps 20rem.
Exercise
Why does width: 300px; width: var(--max); fail to give a fallback in a browser that cannot parse the value stored in --max?
Show answer
The browser accepts any var() declaration at parse time. It finds the value invalid only at computed-value time, and then uses the property's initial or inherited value instead of the earlier declaration. Wrap the rule in @supports to avoid this.