Feature detection and progressive enhancement
Definition and purpose
Progressive enhancement begins with a usable baseline, then enables optional behavior when support is detected. Feature queries test whether the browser accepts a specified CSS feature.
Baseline survives
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { display: block; } @supports (display: not-a-layout) { #a { display: grid; } } </style> </head> <body> <div id="a"> <div id="b">One</div> <div id="c">Two</div> </div> </body></html>The intentionally invalid value keeps the enhancement inactive.
Syntax and mental model
Use @supports (display: grid) for a grid enhancement and selector(:has(*)) for selector support. CSS.supports provides analogous checks in script. A true result does not establish correct layout, accessibility or interoperability. Keep the fallback outside the query. Test by disabling the enhancement in a copy, and by using target browsers. A fabricated unsupported value in a local fixture exercises the false branch only, not an old browser engine.
Enhance to grid
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { display: block; } @supports (display: grid) { #a { display: grid; grid-template-columns: 100px 100px; gap: 8px; } } </style> </head> <body> <div id="a"> <div id="b">One</div> <div id="c">Two</div> </div> </body></html>The supported branch positions the second item after the first track and gap.
Common mistakes
Do not put essential content or all baseline styles inside a support query. Do not assume one property test covers every related subfeature.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: At-rule taxonomy and placement. Next lesson: Legacy and vendor-prefixed CSS.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Feature detection and progressive enhancement — knowledge check
Five questions on feature detection and progressive enhancement.
What should a fallback provide?
Which construct tests CSS declarations?
What does CSS.supports not guarantee?
How can you exercise a fallback locally?
Which additional evidence matters?