---
title: "CSS Supports Nesting Now"
description: "CSS nesting is finally supported in all major browsers. Write cleaner, organized stylesheets without Sass or Less"
canonical: "https://www.trevorlasn.com/blog/css-supports-nesting-now"
author: "Trevor I. Lasn"
published: "2024-12-06"
last-updated: "2026-11-08"
topics: ["CSS"]
---

# CSS Supports Nesting Now

CSS nesting is finally supported in all major browsers. Write cleaner, organized stylesheets without Sass or Less

By Trevor I. Lasn · Published 2024-12-06 · Updated 2026-11-08 · https://www.trevorlasn.com/blog/css-supports-nesting-now

Writing CSS used to mean lots of repetition. For years, we had to write long selectors to style nested elements. Now, native CSS nesting changes everything.

I used SCSS for years just to get nesting in my CSS. But now browsers support nesting right out of the box. No build tools needed. Let me show you how it works.

## Update: Native nesting can't build BEM class names

I carried the `&--large` and `&--small` rules in the button example below over from Sass, and they don't work in native CSS. Native nesting doesn't join strings into new class names: as [MDN explains](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Nesting/Using#concatenation_is_not_possible), the part after `&` is read as a type selector, which makes the rule invalid, so browsers drop it. The example now uses `&.button--large`, which matches `<button class="button button--large">`.

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

Remember writing CSS like this?

```scss title="CSS" del={1-4}
.card { background: white; }
.card .title { font-size: 1.5rem; }
.card .body { padding: 1rem; }
.card .footer { border-top: 1px solid #eee; }
```

Now we can write it like this:

```scss title="CSS" ins={1-6}
.card {
  background: white;
  .title { font-size: 1.5rem; }
  .body { padding: 1rem; }
  .footer { border-top: 1px solid #eee; }
}
```

The nested version is more concise and shows the relationship between elements more clearly. The indentation reflects the DOM structure.

CSS nesting works with any valid selector. Here's how you can nest different types:

```scss title="CSS"
.blog {
  /* Class selectors */
  .title { /* ... */ }
  
  /* Element selectors */
  p { /* ... */ }
  
  /* Attribute selectors */
  [data-type="feature"] { /* ... */ }
  
  /* Pseudo-classes */
  :hover { /* ... */ }
  
  /* Combinations */
  .title:hover { /* ... */ }
}
```

The `&` symbol represents the parent selector. It's particularly useful for modifiers and pseudo-classes:

```scss title="CSS"
.button {
  background: blue;
  color: white;
  
  &:hover {
    background: darkblue;
  }
  
  &.button--large {
    padding: 1rem 2rem;
  }
  
  &.button--small {
    padding: 0.5rem 1rem;
  }
}
```

You can nest media queries too, keeping related styles together:

```scss title="CSS"
.card {
  padding: 1rem;
  
  @media (min-width: 768px) {
    padding: 2rem;
    
    .title {
      font-size: 2rem;
    }
  }
}
```

<br />

### Browser Support and Fallbacks

As of late 2023, CSS nesting is supported in all major browsers. Still, if you need to support older browsers, you have options:

1. Use [@supports](https://www.trevorlasn.com/blog/detect-css-features-with-supports-property) to provide fallbacks
2. Use a CSS preprocessor
3. Use PostCSS with the nesting plugin

Here's how you can use [@supports](https://www.trevorlasn.com/blog/detect-css-features-with-supports-property) to provide a fallback:

```scss title="CSS"
/* Fallback for older browsers */
.card .title { font-size: 1.5rem; }

@supports (selector(&)) {
  .card {
    .title { font-size: 1.5rem; }
  }
}
```

<br />

### Best Practices
While nesting is powerful, it's important to use it judiciously:

1. Avoid deep nesting (more than 3 levels) as it can make styles hard to maintain
2. Use BEM or similar naming conventions to keep specificity in check
3. Consider the output CSS and performance implications
4. Keep selectors as shallow as possible
