---
title: "CSS @supports: Write Future-Proof CSS"
description: "Use CSS @supports to check whether a browser supports a feature such as grid, and give other browsers a fallback. How it works, with multiple conditions."
canonical: "https://www.trevorlasn.com/blog/detect-css-features-with-supports-property"
author: "Trevor I. Lasn"
published: "2024-12-06"
last-updated: "2024-12-06"
topics: ["CSS"]
---

# CSS @supports: Write Future-Proof CSS

Use CSS @supports to check whether a browser supports a feature such as grid, and give other browsers a fallback. How it works, with multiple conditions.

By Trevor I. Lasn · Published 2024-12-06 · https://www.trevorlasn.com/blog/detect-css-features-with-supports-property

I use `@supports` constantly to check if browsers can handle modern CSS features. Think of it as a safety net for your styles - if a browser doesn't support a feature, you can provide a solid fallback.

[Browser support for `supports` on webstatus.dev](https://webstatus.dev/features/supports)

Here's what it looks like in practice:

```scss title="CSS"
/* Fallback for all browsers */
.card {
  display: block;
  margin: 1rem;
}

/* Only applied if grid is supported */
@supports (display: grid) {
  .card {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
  }
}
```

<br />

### How `@supports` Works

The `@supports` rule checks if a browser understands a CSS property-value pair. You can test for single or multiple features:

```scss title="CSS"
/* Single feature check */
@supports (display: flex) {
  /* Flex styles here */
}

/* Multiple features using and */
@supports (display: flex) and (gap: 1rem) {
  /* Styles that need both flex and gap */
}

/* Alternative features using or */
@supports (display: flex) or (display: grid) {
  /* Styles for either flex or grid */
}

/* Checking for lack of support using not */
@supports not (display: grid) {
  /* Fallback styles for browsers without grid */
}
```

Here's how I use `@supports` to progressively improve a layout:

```scss title="CSS"
.layout {
  /* Base styles using flexbox */
  display: flex;
  flex-wrap: wrap;
  margin: -0.5rem;
}

.layout > * {
  flex: 1 1 300px;
  margin: 0.5rem;
}

/* Enhance with grid and gap if supported */
@supports (display: grid) and (gap: 1rem) {
  .layout {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    margin: 0;
  }

  .layout > * {
    margin: 0;
  }
}
```

<br />

### Testing Multiple Properties

Sometimes you need to test for multiple CSS properties. Here's how to handle complex feature detection:

```scss title="CSS"
@supports (
  (backdrop-filter: blur(10px)) or 
  (-webkit-backdrop-filter: blur(10px))
) {
  .glass-effect {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.5);
  }
}
```

<br />

### Best Practices

1. Start with solid fallback styles that work everywhere
2. Use `@supports` to enhance the experience with modern features
3. Test features individually when possible
4. Consider using multiple `@supports` rules for different feature combinations
5. Keep fallback code maintainable - don't create overly complex style overrides
