CSS @supports At-Rule

The @supports at-rule applies CSS conditionally when a browser recognizes a specified feature.

Use it to progressively enhance a design while preserving usable fallback styles for browsers that do not support the tested syntax.

Syntax

@supports (display: grid) {
  .layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

The condition follows @supports in parentheses. The enclosed declarations are considered only when the feature test succeeds.

How @supports Works

Feature queries test whether a browser recognizes particular CSS syntax, rather than identifying the browser by name. If the condition is false, the browser ignores the conditional rules and retains other applicable styles.

A successful syntax test does not guarantee identical visual results across engines. Feature queries should complement, not replace, testing.

Declaration Tests

@supports (display: grid) {
  .gallery { display: grid; }
}
@supports (color: color(display-p3 1 0 0)) {
  .highlight { color: color(display-p3 1 0 0); }
}

Each declaration test checks a property and value together. Testing a property alone is not sufficient to establish support for a particular value.

Logical Operators

@supports (display: grid) and (gap: 1rem) {
  .gallery { display: grid; gap: 1rem; }
}
@supports not (display: grid) {
  .gallery { display: block; }
}
@supports (display: grid) or (display: flex) {
  .gallery { max-width: 60rem; }
}

Use and when all tests must pass, or when any test may pass, and not to negate a test. Parenthesize individual conditions clearly.

Selector Tests

@supports selector(:has(> img)) {
  .card:has(> img) {
    padding: 1rem;
  }
}

selector() tests whether a selector is recognized. It does not test whether a matching element exists in the document.

Progressive Enhancement

.layout {
  display: block;
}
@supports (display: grid) {
  .layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }
}

Place readable baseline styles outside the conditional rule. Browsers that support the tested feature receive the enhancement, while others retain the baseline.

JavaScript Feature Tests

CSS.supports("display", "grid");
CSS.supports("(display: grid) and (gap: 1rem)");
CSS.supports("selector(:has(> img))");

The CSS.supports() method returns a boolean. It accepts a property-value pair or a complete condition string.

@supports Example

This example uses a two-column layout when Grid is recognized. The existing editor lets you change the condition and inspect the result.

HTML

<div class="layout">
  <div>First column</div>
  <div>Second column</div>
</div>

CSS

.layout { display: block; }
@supports (display: grid) {
  .layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }
}

Play in Editor

Browser Support

@supports is widely available in modern browsers. Whether a condition succeeds depends on the tested CSS feature. Consult Can I Use? for the individual feature and maintain fallback styles for older browsers.

Specifications

The @supports at-rule is defined in CSS Conditional Rules Module Level 3.

CSS Conditional Rules Module Level 3