CSS Reference ยท At-rules
The @supports at-rule
Reference for the CSS @supports at-rule: test whether the browser understands a property, value or selector, use not, and, or, with live examples.
The @supports at-rule is a feature query. It asks the browser "can you parse this declaration (or selector)?" and applies the rules inside only if the answer is yes. That lets you use a modern feature where it exists and keep a safe layout elsewhere.
The test is about parsing, not about visual correctness: a browser that accepts the syntax but implements the feature poorly still says yes.
@supports (display: grid) { .gallery { display: grid; } }
Try it
Syntax
@supports <supports-condition> { /* rules */ } @supports (property: value) { } @supports not (property: value) { } @supports (a: b) and (c: d) { } @supports (a: b) or (c: d) { } @supports selector(<selector>) { } @supports font-tech(color-COLRv1) { }
- Parentheses are required around each declaration test, and you cannot mix
andwithorat the same level without extra parentheses. - Value is checked too.
(display: grid)tests the property and that value. - Nesting:
@supportscan contain other conditional at-rules and can sit inside style rules.
Values
| Syntax and arguments | Description |
|---|---|
(prop: value) |
True if the browser parses this declaration. |
not (...) |
Negation. |
(...) and (...) |
Both must be supported. |
(...) or (...) |
At least one must be supported. |
selector(...) |
True if the browser parses the selector, such as selector(:has(a)). |
font-tech(...), font-format(...) |
Tests font technologies used with @font-face. |
Usage notes
- Write the fallback first. Put the old-style rule outside the query, and the modern override inside it. Browsers that ignore
@supportsaltogether are rare and get the fallback. - Don't wrap everything. For a single property with an easy fallback, just write two declarations in a row; the browser keeps the last one it understands. Reach for
@supportswhen you must change several things together, like switching a whole layout. - Testing a custom property value is unreliable, because custom properties accept almost anything.
notneeds parentheses:@supports not (display: grid), not@supports not display: grid.- It tests syntax only. A property might parse but still be buggy;
@supportscannot know that. - Prefixed properties like
(-webkit-appearance: none)can be tested too.
Browser support
Supported in all modern browsers. The selector() function is Baseline since 2022; font-tech() and font-format() are newer, so test them before relying on them.
Related
@media@container@font-face- Lesson: Feature Queries
- Lesson: At-rules