Sub topic 1
Progressive enhancement: start with a working baseline
Progressive enhancement is a way of building pages in layers. You write a version that works in every browser you support, then add improvements for browsers that can handle them. This chapter explains the idea, compares it with graceful degradation, and shows how to choose a baseline. The rest of the tutorial gives you the CSS tools, mainly @supports, that make the layering practical.
Prerequisites
This chapter assumes you already know:
- Basic CSS syntax: selectors, properties and values.
- How the cascade and source order decide between conflicting declarations.
- What an at-rule such as
@medialooks like.
You do not need JavaScript for this chapter. Later chapters use it briefly.
The core idea
A web page runs on browsers you do not control. They differ in version, engine, settings, screen size, input method and network quality. A feature you use today may be missing in a browser a visitor installed years ago, or in an embedded web view inside another app. A stylesheet written only for the newest browser breaks for those visitors.
Progressive enhancement addresses this with an order of work:
- Write meaningful HTML. The content and its structure are the foundation.
- Add CSS that every supported browser understands. This is the baseline.
- Add improvements that apply only where the browser supports them.
Each layer depends on the one below it. No layer is required for the one below it to work. If an enhancement is not applied, the visitor still gets a complete, usable page.
What "baseline" means
The baseline is not "the worst possible experience". It is the experience you commit to delivering everywhere you support. You choose it deliberately, and you can write it down. For example:
- Content is readable and in a logical order.
- All links and forms work.
- The layout fits the screen without horizontal scrolling.
- Text has enough contrast.
The baseline does not have to look identical to the enhanced version. It has to be correct and usable.
Progressive enhancement versus graceful degradation
The two terms are often mixed up. They describe different starting points.
| Aspect | Progressive enhancement | Graceful degradation |
|---|---|---|
| Starting point | The simplest working version | The full-featured version |
| Direction of work | Add features upward | Patch failures downward |
| Typical question | "What can I add where it is supported?" | "What breaks where it is not supported?" |
| Failure mode | A browser misses some polish | A browser may miss something essential |
| Testing focus | The baseline first | The newest browser first |
Graceful degradation is not wrong, but it leaves a gap. You design for the best case and then try to anticipate each way it can fail. Old or unusual browsers are hard to test, so the fallbacks you write are often incomplete. With progressive enhancement the safe version exists first, so a missed case costs polish instead of function.
A worked example: an image gallery
Suppose you build a gallery of cards. The semantic HTML comes first:
<ul class="gallery">
<li><img src="a.jpg" alt="A lighthouse at dusk"></li>
<li><img src="b.jpg" alt="A fishing boat in harbor"></li>
<li><img src="c.jpg" alt="A rocky coastline"></li>
<li><img src="d.jpg" alt="Waves breaking on a pier"></li>
</ul>Without any CSS, this is already a usable list of labeled images. That is layer one.
The baseline CSS uses flexbox, which has very broad support:
.gallery {
display: flex;
flex-wrap: wrap;
gap: 1rem;
list-style: none;
padding: 0;
}
.gallery > * {
flex: 1 1 12rem;
}
.gallery img {
display: block;
width: 100%;
height: auto;
}The items wrap onto new rows and share the available width. The last row may have fewer items, and those items stretch wider than the others. That is acceptable for a baseline.
Now add an enhancement on top. A grid layout keeps every column the same width, including in the last row:
@supports (display: grid) {
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
}
}The @supports rule is a conditional at-rule, like @media. The browser applies the rules inside it only if it supports the condition in parentheses. A browser without grid ignores the block and keeps the flexbox layout. A browser with grid applies it. You will study the syntax in detail in a later chapter. For now, notice the structure: baseline first, enhancement second, and the enhancement sits inside a clearly marked block.
Why the order matters
The enhancement comes after the baseline in source order. Both rules have the same specificity, so the later rule wins wherever it applies. Reverse the order and the flexbox rules would override the grid declaration. The display: flex would win over display: grid in every browser, and the enhancement would never show.
Keep this habit: baseline rules above, enhancement rules below.
Cleaning up leftovers from the baseline
The enhanced layout also inherits declarations from the baseline. In the example, the .gallery > * rule sets flex: 1 1 12rem. Once .gallery becomes a grid, its children are grid items and the flex property has no effect on them, so it is harmless. That is not always the case. When a baseline declaration conflicts with an enhancement, you must reset it inside the enhancement block. Check each enhancement for properties that now interact in unwanted ways.
Choosing a baseline
There is no single correct baseline. You pick one by weighing a few factors:
- Your audience. Check analytics and the devices your users actually use. A corporate intranet on managed browsers has a different baseline from a public site visited from old phones.
- Your support policy. Many teams write down a list of supported browsers. The baseline must work in all of them.
- The cost of the fallback. If a fallback is one extra line, write it. If it requires a separate system of rules and doubles your testing, reconsider whether the feature is worth it.
- The role of the feature. Decorative features, such as shadows, blurs and animations, are easy to leave out. Structural features, such as the main layout, need a fallback that is just as functional.
When no fallback is needed
Not everything needs a conditional block. A feature with near-universal support can go straight into the baseline. Flexbox is a common baseline for exactly this reason. Writing @supports around everything makes the stylesheet harder to read. Use it where a real difference in support exists among the browsers you target.
What makes a good enhancement
A good enhancement improves the experience without becoming a requirement. These criteria help you judge a candidate:
- The page works without it. If removing the enhancement leaves text unreadable or controls unreachable, it is not an enhancement. It is a dependency.
- It fails quietly. An unsupported browser should skip the rule with no visible error, broken layout or jump in content.
- It is contained. The enhancement lives in one clearly named block, so you can find it, change it or delete it later.
- It does not change meaning. Visual differences are fine. Hiding information, or reordering it in a way that changes how it reads, is not.
Example: a translucent panel
A translucent panel with a blurred background looks good, but the blur is optional. The baseline makes the panel nearly opaque, so the text stays readable without the blur. The enhancement makes it translucent only where the blur is available.
.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 order of the two pieces matters. If you made the panel translucent first and then added blur as an extra, a browser without blur would show text over a busy background with poor contrast. By starting opaque, the unsupported case remains legible. This is the kind of reasoning that distinguishes a baseline-first design from a degraded one.
Edge cases and failure modes
Progressive enhancement is simple in principle, but several situations cause trouble in practice.
Partial support
A browser may support a feature in part. It may accept a property but not every value, or implement an older version of the specification. A check for the property name alone can then pass when the value you need does not. Test the exact property and value pair you rely on, not only the property name. The next chapters show how.
Support is not the same as correct behavior
A browser can pass a feature check and still contain a bug in that feature. Feature detection tells you the browser claims to understand the syntax. It does not tell you the result will look right. For critical layouts, test in real browsers.
Enhancements that change layout dimensions
Some enhancements change the size of elements, such as a switch from flex to grid. This can cause layout shifts if a script or other styles depend on the baseline sizes. Keep the baseline and the enhanced layout close enough that content does not jump or overlap.
Too many layers
Every enhancement adds a path to test. A page with ten independent enhancements has many possible combinations of supported and unsupported features. Keep enhancements small, independent and few. Prefer ones that do not interact.
Hidden dependencies
An enhancement can quietly become a requirement. A design may rely on grid-only spacing, or a script may expect a class that only the enhanced layout provides. Review the page with the enhancements off. If something breaks, move that piece of logic back into the baseline.
Where @supports fits
Progressive enhancement is a way of working. @supports is one of its tools. Two others appear in this tutorial:
- The cascade itself provides fallbacks. A browser drops a declaration it cannot parse and keeps the previous one.
CSS.supports()lets JavaScript run the same checks.
The @supports rule is most useful when one feature needs several related declarations, or when a rule must apply only if a feature exists. The cascade is simpler when a single declaration has a safe predecessor. Later chapters explain how to choose between them.
Putting it into practice
When you start a new component, you can follow a short routine:
- Write the HTML so it makes sense with no styling.
- Write baseline CSS using features supported by every browser on your list.
- List the improvements you want, such as a better layout, a blur or a conditional border.
- For each improvement, decide what the page looks like without it. If that version is acceptable, proceed.
- Add the enhancement after the baseline, in a clearly marked block.
- Test with the enhancement active and, where you can, with it disabled.
Exercise
A developer writes a card layout with display: grid and no fallback, because "all modern browsers support grid". A visitor opens the page in an old embedded web view that lacks grid, and the cards stack in a broken layout. Which approach would have prevented this? Name the baseline and the enhancement.
Show answer
Progressive enhancement. The baseline would be a layout that works everywhere, such as flexbox with flex-wrap, or even plain block flow. The enhancement would be display: grid placed after it, inside @supports (display: grid). Browsers without grid keep the baseline layout, and browsers with grid get the improved one.
Exercise
You add a blurred translucent panel and set its background to rgb(255 255 255 / 0.5) in the base .panel rule. The blur is placed inside an @supports block. Why is this a problem for browsers without backdrop-filter, and how do you fix it?
Show answer
Those browsers keep the 0.5 translucent background without any blur, so text sits over whatever is behind the panel and may be hard to read. Fix it by making the baseline background nearly opaque, such as rgb(255 255 255 / 0.95). Then lower the opacity only inside the @supports block, together with the blur.
Exercise
In the gallery example, why must the @supports (display: grid) block come after the flexbox rules in the stylesheet?
Show answer
Both rules have the same specificity, so the later one wins in browsers that match both. If the @supports block came first, the later display: flex would override display: grid, and the grid enhancement would never take effect.