CSS parsers generally discard an invalid declaration while continuing with the rest of the stylesheet. A later valid declaration can replace an earlier fallback when the browser understands it.
CSS invalid declarations and fallbacks: fail locally, not silently
When to use it
A report panel uses a basic solid border and a newer color function for a softer theme. Keep the plain color first, then add the enhanced value in a later declaration. An older browser ignores a declaration it cannot parse and retains the preceding valid one. A syntactically valid custom property can still produce an invalid value when substituted at computed-value time, which is a different failure path; inspect the actual computed style. Do not assume that a successful stylesheet download means every declaration applied. Test the component with a known unsupported value in a local sandbox, not in production, to see how the fallback behaves. Comments can document a compatibility decision, but they should not hide a copied pile of unexplained overrides.
.report-panel { border: 1px solid #aebfcb; background-color: #f2f6f8; }
@supports (color: color-mix(in srgb, black, white)) {
.report-panel { background-color: color-mix(in srgb, #f2f6f8 85%, #d4e3ec); }
}Cost and verification
A fallback can increase CSS bytes slightly, but it avoids a broken surface on unsupported clients. The real cost is maintaining two paths and testing both. @supports checks parsing support for the feature condition, not color contrast or the meaning of a whole component. Verify the final surface against its text in each path. Avoid placing a fallback after the enhanced declaration, where it would override the enhancement by source order. Keep related declarations near each other so reviewers can see the intended progression.
Common Mistakes
- Do not read a successful network response as proof every rule applied.
- Do not put the fallback after the enhancement in the same cascade position.
- Do not expect @supports to verify accessibility or business behavior.
