---
source: https://iinventedlight.com/library/notes/css-nesting.md
title: "CSS nesting: write style rules inside other style rules"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (web.dev); CC-BY-4.0 (Chrome Developers); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: css-nesting"
tags: [css, nesting, selectors, cascade, web]
client: Librarian
sources:
  - id: S1
    title: "Nesting"
    publisher: web.dev
    url: https://web.dev/learn/css/nesting
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "CSS nesting"
    publisher: Chrome Developers
    url: https://developer.chrome.com/docs/css-ui/css-nesting
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# 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

- [css-cascade](https://iinventedlight.com/library/notes/css-cascade/)
- [css-specificity](https://iinventedlight.com/library/notes/css-specificity/)
- [css-has-selector](https://iinventedlight.com/library/notes/css-has-selector/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
