Skip to main content

The CSS @supports Rule

Use the @supports rule to ask the browser if it supports a specific CSS property or value. Fallback styles for an unsupported feature can be defined with it too.

As a result, styles only apply when the browser is able to handle them.

Basic Syntax

styles.css
@supports (property: value) {
  /* CSS rules to apply if condition is true */
}

Example: Using @supports with grid and flex

Fallback styling comes from pairing @supports with regular CSS.

Flex fallback

A browser that supports display: flex applies the CSS inside the @supports rule. Any other browser uses the .container class written outside it instead.

Prompt
Create a page that uses @supports to check if the browser supports display: flex. If supported, style a .container with display: flex. Outside the @supports rule, provide a fallback using float: left and width: 100% for the .container. Add a few child items inside the container to demonstrate the layout.
Output: complete HTML page

Grid fallback

Here the test is display: grid. When it passes, the CSS inside the @supports rule applies, and when it fails, the .container class outside that rule serves as a fallback.

Prompt
Create a page that uses @supports to check if the browser supports display: grid. If supported, style a .container with display: grid, grid: auto, grid-gap: 10px, background-color: #2196F3, and padding: 10px. Outside the @supports rule, provide a fallback with display: table, width: 90%, same background color and padding. Add several child items to show the layout.
Output: complete HTML page

Negating with not

To apply styles only when a feature is not supported, write not in the condition.

Example

styles.css
@supports not (display: grid) {
  .warning {
    background-color: pink;
    padding: 10px;
    border: 1px solid red;
  }
}

Combining Conditions

A single @supports rule can hold multiple conditions, joined with and, or, and not.

Note: Older browsers need fallback styles, so always provide them outside of @supports.

Example

styles.css
@supports (display: grid) and (gap: 10px) {
  .container {
    display: grid;
    gap: 10px;
  }
}

CSS Reference

Whether a browser supports a CSS feature is tested with the @supports at-rule.