- Home
- /
- Tutorials
- /
- CSS Tutorial
- /
- Feature Queries
CSS Responsive Design
Feature Queries
Apply progressive enhancements only when the browser understands a required CSS declaration or selector. It covers declaration queries, selector queries, combined conditions, progressive enhancement, and the limits of syntax-based support detection.
@supports asks the browser a simple question: "do you understand this piece of CSS?" If yes, the rules inside apply; if not, they are skipped. It lets you use new features without breaking the page in older browsers.
The idea is to write a simple layout that works everywhere first, then add the better version inside @supports. It is the same "test the space, not the device" thinking as Container Queries, and it can be nested inside rules, as shown in Nesting & Scope.
Test a feature, not a browser
Example
css
.layout { display: block; }
@supports (display: grid) {
.layout {
display: grid;
grid-template-columns: 16rem 1fr;
}
}
@supports selector(:has(*)) {
.field:has(:invalid) { border-color: #b91c1c; }
}Every browser gets a normal block layout. Browsers that support Grid get a two-column layout instead. The second rule uses selector() to check for :has() support before relying on it to color invalid fields.
Checking for a feature is far more reliable than checking for a browser name. Browsers update constantly, and the user-agent string lies.
Combine conditions
Example
css
@supports (text-wrap: balance) and (font-size: 1cqi) {
.card-title {
text-wrap: balance;
font-size: clamp(1.25rem, 4cqi, 2rem);
}
}and, or and not work like in media queries. This title gets balanced wrapping and container-relative font sizing only if both are supported.
Feature Query Syntax
| Condition | Tests | Example |
|---|---|---|
| Declaration | Whether a property-value pair parses. | @supports (display: grid) |
| selector() | Whether a selector parses. | @supports selector(:has(*)) |
| not | The inverse of a support condition. | @supports not (display: grid) |
| and / or | A combination of support conditions. | @supports (a: b) and (c: d) |
Complete Example
Complete runnable example
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Feature Queries example</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 2rem;
font-family: system-ui, sans-serif;
line-height: 1.5;
}
main { max-width: 70rem; margin-inline: auto; }
article, section, aside, form, .card, .panel {
padding: 1rem;
border: 1px solid #cbd5e1;
border-radius: 0.6rem;
}
.layout { display: block; }
@supports (display: grid) {
.layout {
display: grid;
grid-template-columns: 16rem 1fr;
}
}
@supports selector(:has(*)) {
.field:has(:invalid) { border-color: #b91c1c; }
}
@supports (text-wrap: balance) and (font-size: 1cqi) {
.card-title {
text-wrap: balance;
font-size: clamp(1.25rem, 4cqi, 2rem);
}
}
</style>
</head>
<body>
<main class="layout"><label class="field">Required email <input type="email" required value="not-an-email"></label><article><h1>Progressive enhancement</h1><p>Grid and :has() styles are added only when supported.</p></article></main>
</body>
</html>Browser Support
Feature | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|
| @supports | 28 | 12 | 22 | 9 |
Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8. A partial-support note is included where it changes how the example behaves.
Good to know
@supportschecks whether the browser understands the syntax, not whether the feature is bug-free.- Often you do not need it at all. If a browser does not understand a declaration, it just ignores that line, so writing the old value first and the new one after is enough:
width: 90%; width: min(90%, 60rem);. - Use
@supportswhen the new feature only works together with other rules, like a whole Grid layout that would look broken without its companions.
Feature Queries exercises
Test for a feature
Make the row a grid only if the browser supports display: grid.
The HTML your code works on
<div class="row">
<div>1</div>
<div>2</div>
</div>Result
