@supports
Applies styles only in browsers that support a given property, value, or selector. It lets you use new features safely.
Example
#.header {
background: rgb(24 24 27 / 0.95);
}
@supports (backdrop-filter: blur(8px)) {
.header {
background: rgb(24 24 27 / 0.55);
backdrop-filter: blur(8px);
}
}<style>
.page { position: relative; height: 130px; overflow: hidden; border-radius: 12px; background: #0c0c10; }
.header { position: absolute; inset: 0 0 auto; padding: 12px 16px; font-weight: 600; }
.tiles { display: flex; gap: 10px; padding: 24px 16px; }
.tiles .box { flex: 1; min-height: 76px; }
</style>
<div class="page">
<div class="tiles"><div class="box">HTML</div><div class="box">CSS</div><div class="box">JS</div></div>
<header class="header">CodeWorlds · Documentation</header>
</div>The bar is semi-transparent and blurs the tiles beneath it only where backdrop-filter works. A browser without this feature will show an almost opaque bar, so the text stays readable anyway.
Definition and usage
#The @supports rule asks the browser whether it understands a given syntax. In parentheses you provide a declaration, e.g. (display: grid), and the browser checks whether it knows both the property and that value. If so, the styles in the block apply. If not, the whole block is skipped.
A typical pattern is progressive enhancement. Outside the rule you write a simple style that works everywhere, and in @supports you add the newer version. The opposite form, @supports not (…), holds a fallback only for browsers that do not know the feature.
You combine conditions with and and or, and each must be in its own parentheses. The selector() function checks selector support, e.g. selector(:has(img)). This matters because a single unknown selector in a list invalidates the whole rule, and in @supports you can prepare a replacement for it.
Remember that @supports only checks whether the browser recognizes the syntax, not whether the feature works without errors in every detail. You also do not need it for every new feature: the browser silently skips an unknown declaration anyway. The rule is useful only when other styles depend on the support.
Syntax
#@supports (<property>: <value>) {
selector { property: value; }
}
@supports not (<condition>) { … }
@supports (<condition>) and (<condition>) { … }
@supports (<condition>) or (<condition>) { … }
@supports selector(<selector>) { … }Kinds of conditions
#a property and value
Every modern browser knows grid, so the block applies and the tiles line up in three columns. Without it they would stay one below the other.no support
The block applies only where grid is missing, that is, in very old browsers. Here it does not apply, so the tiles stay one below the other, as in the base style.selector support
Checks a selector instead of a declaration. Hover over a tile: the others fade. The rule with:has()works only in browsers that know this selector.both conditions at once
The block applies only when the browser supports grid andaspect-ratio. The tiles line up in a row and become square.at least one condition
One satisfied condition is enough. This is how you check prefixed properties: the glass blurs the tiles beneath it if the browser knowsbackdrop-filterin either version.
Kinds of conditions in practice
#(display: grid)
@supports (display: grid) {
.demo {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
}not (display: grid)
@supports not (display: grid) {
.demo { flex-direction: row; }
}selector(:has(*))
:has() works only in browsers that know this selector.@supports selector(:has(*)) {
.demo:has(.box:hover) .box:not(:hover) {
opacity: 0.3;
}
}(…) and (…)
aspect-ratio. The tiles line up in a row and become square.@supports (display: grid) and (aspect-ratio: 1) {
.demo {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.demo .box { aspect-ratio: 1; }
}(…) or (…)
backdrop-filter in either version.@supports (backdrop-filter: blur(6px))
or (-webkit-backdrop-filter: blur(6px)) {
.glass {
background: rgb(255 255 255 / 0.12);
-webkit-backdrop-filter: blur(6px);
backdrop-filter: blur(6px);
}
}More examples
#.card {
display: grid;
gap: 10px;
}
@supports (container-type: inline-size) {
.slot {
container-type: inline-size;
}
@container (width >= 300px) {
.card {
grid-template-columns: 80px 1fr;
align-items: center;
}
}
}<style>
.card { padding: 10px; border: 1px solid #27272a; border-radius: 12px; background: #18181b; }
.thumb { height: 56px; border-radius: 8px; background: linear-gradient(135deg, #10b981, #0ea5e9); }
.card p { margin: 2px 0 0; color: #a1a1aa; font-size: 13px; }
</style>
<div class="slot">
<article class="card"><div class="thumb"></div><div><strong>CSS Grid</strong><p>Module 8 · 10 lessons</p></div></article>
</div>The simplest way to check for container query support is through the container-type property, which arrived together with them. A browser without this feature will simply show a vertical card.
Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Write the base style outside the rule, and put in
@supportsonly what requires the new feature. An older browser will get a simpler but working look. - You can check support for an at-rule through the property that came with it, e.g.
@supports (container-type: inline-size)before using@container. - For prefixed properties, check both versions with
or, e.g.(backdrop-filter: blur(4px)) or (-webkit-backdrop-filter: blur(4px)).
Related entries
#- @mediaApplies styles only when the device meets a condition: a matching window width, a dark theme, a mouse, or printing the page.
- @containerApplies styles based on the size of a container instead of the whole window. A component adapts to the space it gets in the layout.
- :has()Selects an element based on what it contains or what follows it. Lets you style a parent according to its children.
- backdrop-filterApplies a filter to what is visible behind an element, for example blurring the background behind a panel.
- displayDetermines how an element behaves in the page layout and how it lays out its children.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.