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
- id: C1 claim: Nesting can make stylesheets more organized and maintainable. source: S1 evidence: "more organized, easier to read, and more maintainable"
- id: C2 claim: A nested rule defaults to a descendant combinator. source: S1 evidence: "descendant combinator"
- id: C3 claim: The & selector cannot represent pseudo-elements. source: S1 evidence: "can't represent pseudo-elements"
- id: C4 claim: Before nesting, each selector had to be declared separately. source: S2 evidence: "explicitly declared, separately"
- id: C5 claim: Nesting reduces repeated selectors and groups related rules. source: S2 evidence: "reducing the need to repeat selectors"
- id: C6 claim: Classes nested without & become descendant selectors. source: S2 evidence: "without & will always result in descendant selectors"
Sources
- [S1] Nesting. web.dev. https://web.dev/learn/css/nesting . License: CC-BY-4.0. Accessed 2026-11-23.
- [S2] CSS nesting. Chrome Developers. https://developer.chrome.com/docs/css-ui/css-nesting . License: CC-BY-4.0. Accessed 2026-11-23.
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
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.},
}
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.
- css-nesting.schema.json (schema; CC-BY-4.0)
- css-nesting.table.json (table; CC-BY-4.0)
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.