e01.org

CSS nesting

The CSS nesting module defines a syntax for nesting selectors, providing the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule.

The **CSS nesting** module defines a syntax for nesting selectors, providing the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule.

CSS nesting is different from CSS preprocessors such as [Sass](https://sass-lang.com/) in that it is parsed by the browser rather than being pre-compiled by a CSS preprocessor.

CSS nesting helps with the readability, modularity, and maintainability of CSS stylesheets. It also potentially helps reduce the size of CSS files, thereby decreasing the amount of data downloaded by users.

## Reference

### Selectors

- [`&` nesting selector](/docs/Web/CSS/Reference/Selectors/Nesting_selector)

## Guides

- [Using CSS nesting](/docs/Web/CSS/Guides/Nesting/Using)
- : Explains how to use CSS nesting.
- [CSS nesting at-rules](/docs/Web/CSS/Guides/Nesting/At-rules)
- : Explains how to nest at-rules.
- [CSS nesting and specificity](/docs/Web/CSS/Guides/Nesting/Nesting_and_specificity)
- : Explains the differences in specificity when nesting CSS.

## Related concepts

- [Selectors and combinators](/docs/Web/CSS/Guides/Selectors/Selectors_and_combinators)
- [Pseudo-classes](/docs/Web/CSS/Reference/Selectors/Pseudo-classes)
- [CSS preprocessor](/docs/Glossary/CSS_preprocessor)

## Specifications

## See also

- [Specificity](/docs/Web/CSS/Guides/Cascade/Specificity)
- [CSS cascading and inheritance module](/docs/Web/CSS/Guides/Cascade)
- [CSS selectors module](/docs/Web/CSS/Guides/Selectors)

source: MDN Web Docs mirror · page

Cite this

"CSS nesting". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Nesting

JSON record · API collection · citation policy