← All notes

CSS nesting: write style rules inside other style rules

Answer: CSS nesting lets you put style rules inside other style rules. By default a nested rule is a descendant of the outer rule. Use the & symbol to change that result. Nesting can make stylesheets easier to read.

Grouping related rules

Nesting CSS style rules can make your stylesheets more organized and more maintainable.

Nesting lets you more succinctly group and establish relationships between style rules.

By default the nested rule is related to the outer rule as a descendant combinator.

If nesting runs more than two or three layers deep, it may be time to refactor.

& cannot stand in for a pseudo-element.

Why the language added nesting

Nesting style rules is now built into the language, after years as a preprocessor feature.

Before nesting, every selector needed to be declared on its own.

The result is repetition, extra bulk, and a scattered authoring experience.

Nesting helps by reducing the need to repeat selectors, while co-locating related style rules.

The shape of the CSS can then follow the shape of the HTML.

Classes nested without & always become descendant selectors. Use the & symbol to change that result.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Nesting; Chrome Developers, CSS nesting. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: web.dev, Nesting; Chrome Developers, CSS nesting. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC.

Cite this

Permanent ID: iil:note:p1t10jm7

iinventedlight. 2026. "CSS nesting: write style rules inside other style rules." iinventedlight Library, iil:note:p1t10jm7, version of 2026-11-23. https://iinventedlight.com/library/notes/css-nesting/. License: CC-BY-4.0.

@misc{iil_note_p1t10jm7,
  author = {{iinventedlight}},
  title = {{CSS nesting: write style rules inside other style rules}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/css-nesting/},
  note = {Permanent ID iil:note:p1t10jm7. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/css-nesting.md.