Sub topic 11
Testing Both the Baseline and the Enhanced Experience
This chapter assumes you can write @supports rules, know how the cascade resolves conflicting declarations, and have used CSS.supports() in JavaScript. Writing a fallback is only half the job. You also have to confirm that the fallback works and that the enhancement works. Most teams test only the enhanced version, because that is what their own browser shows.
Why the baseline needs its own test
A baseline is code that runs only when a feature is missing. In day-to-day work, you rarely see it. A typo in the baseline can sit unnoticed for months until someone opens the page in an older browser.
Take the gallery from earlier chapters:
.gallery {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.gallery > * {
flex: 1 1 12rem;
}
@supports (display: grid) {
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
}
}In a modern browser, the @supports block wins and the flexbox rules are overridden. Notice that .gallery > * still sets flex: 1 1 12rem. Grid items ignore flex, so the rule is harmless, but it shows that both layers are active in the enhanced browser. A bug in the flexbox layer would be invisible there.
Three ways to see the baseline
You do not need an old browser to see the baseline. These approaches are listed from fastest to most realistic.
- Disable the enhancement in DevTools. Open the Styles pane, find the rules inside the
@supportsblock, and untick the properties. You see what the page looks like without them. This is quick, but it only approximates the real baseline. - Temporarily break the condition. Change
@supports (display: grid)to@supports (display: not-a-real-value). The condition is now false in every browser, so the block never applies. Remember to change it back. - Test in a real browser that lacks the feature. This is the only way to catch problems such as a missing prefix or a bug in the engine. Use a browser-testing service or an older browser version you keep for this purpose.
Option 2 is the most reliable for everyday development, because the browser applies exactly the code path an unsupported browser would.
What to check in each experience
Use a short checklist for each state. The baseline does not have to look identical to the enhancement, but it must be usable.
| Check | Baseline | Enhanced |
|---|---|---|
| Content is readable | Text has enough contrast, for example on the nearly opaque panel | Text stays readable on the translucent, blurred panel |
| Layout does not break | No overlap, no horizontal scrolling | Grid columns fill the available width |
| Controls work | Links and buttons are reachable and clickable | Same, and `:has()` styles do not hide anything |
| No errors | Console is clean | Console is clean |
The panel example shows why contrast matters:
.panel {
background: rgb(255 255 255 / 0.95);
}
@supports (backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px)) {
.panel {
background: rgb(255 255 255 / 0.6);
-webkit-backdrop-filter: blur(8px);
backdrop-filter: blur(8px);
}
}The enhanced version is the risky one here. Text on a 60 percent opaque background is only readable because the blur softens what is behind it. If the blur fails to render, you have low-contrast text. Check the enhanced state against a busy background image, not only a plain page.
Confirming support from a script
When you cannot tell which branch a browser took, ask it. Run this in the console of the browser under test:
const checks = {
grid: CSS.supports('display', 'grid'),
blur: CSS.supports('(backdrop-filter: blur(4px)) or (-webkit-backdrop-filter: blur(4px))'),
has: CSS.supports('selector(:has(a))'),
};
console.table(checks);The table lists each feature as true or false. This tells you which experience that browser should be showing, so you can compare it with what you see on screen. If grid is true but the page looks like the flexbox layout, something else is overriding your rule, for example a rule with higher specificity.
A repeatable testing routine
Apply this routine each time you add an @supports block. It takes a few minutes and catches the most common failures: a baseline nobody ever viewed, and an enhancement that lowers readability.
Summary
- Test the baseline on purpose, because your own browser hides it.
- Break the
@supportscondition instead of deleting the block. - Verify readability in both states, especially for translucent or blurred effects.
- Use
CSS.supports()in the console to confirm which branch a browser should take. - Finish with a spot check in a real browser that lacks the feature.
Exercise
You added @supports (display: grid) { .gallery { display: grid; } } over a flexbox baseline. Your browser supports grid, so you only ever see the grid layout. Describe how to view the flexbox baseline without editing any other rules, and name one thing to check once you see it.
Show answer
Temporarily change the condition to something no browser supports, for example @supports (display: not-a-real-value), so the block never applies and the flexbox rules show. Reload and check that items wrap, keep their gaps, and cause no horizontal scrolling. Then restore the original condition.
Exercise
In the console, CSS.supports('display', 'grid') returns true, yet the page shows the flexbox layout. What does this tell you about the cause?
Show answer
The browser supports grid, so the @supports condition is true. The enhancement is being overridden by something else, such as a more specific selector, a later rule that sets display, or a typo in the selector inside the block. It is not a missing feature.