Sub topic 1
Progressive enhancement: start with a working baseline
Prerequisites
Assume you know CSS selectors, properties, values, the cascade, source order, and basic at-rules such as @media.
Progressive enhancement: start with a working baseline
Progressive enhancement means starting with a useful experience that works with basic browser capabilities. Then you add improvements when the browser supports them. The baseline should provide readable content, usable controls, and a workable layout.
This approach differs from graceful degradation. Graceful degradation often starts with an advanced design and adds fixes for older browsers. Progressive enhancement starts with the simplest reliable design and builds upward.
.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));
}
}The flexbox layout is the baseline. A browser that supports CSS Grid replaces it with the grid layout. A browser without Grid still receives a usable gallery.
Detect features, not browsers
Feature detection asks whether a capability exists, such as support for display: grid. Browser sniffing examines a user-agent string and guesses which browser is running.
Feature detection is usually safer because browsers can change their user-agent strings, share rendering engines, or support different features at different versions. Test the capability you need instead of maintaining a list of browser names.
The @supports rule performs feature detection in CSS. It evaluates a declaration condition, such as (display: grid), and applies the block only when the browser understands that property and value.
Fallbacks you already get from the cascade
The cascade can provide a fallback without an @supports block. Put the widely supported declaration first and the newer declaration second:
.card {
width: 300px;
width: min(100%, 300px);
}If the browser cannot parse min(), it discards that declaration as invalid and keeps width: 300px. If it understands min(), the later declaration wins.
Exercise
Why should the baseline declaration come before the enhancement?
Show answer
An unsupported enhancement is discarded, leaving the earlier baseline available.