Layout & CSS More detail A2 · Formal specification Platform: Web

CSS Nesting

CSS nesting is built-in syntax for writing one style rule inside another. The browser still follows CSS rules for reading selectors and their weight.

See how it works
You might call it native nestingnested style rules

See how it works

Original worked exampleCSS Nesting

Another example

A button nests `&:hover`, `&:focus-visible`, and `@media (forced-colors: active)` inside `.button`. This keeps six state rules near the base rule. A review rejects three levels of child selectors because they would tie the button to one page structure.

Main parts

  1. 01Parent style rule
  2. 02Nested selector or at-rule
  3. 03Resolved selector

Use it when

Use one or two shallow levels for states, versions, and conditional at-rules that belong to the same component.

Do not use it when

Avoid deep child chains and hidden ties to exact DOM structure. Native nesting does not always act like a CSS preprocessor.

Name used in code

nested style rules with &, relative selectors, and nested group rules

Before you ship

Check content order, shared design values, component consistency, contrast, zoom, and layout changes by screen size. Verify every theme, language, and state. If there is motion, offer an equal reduced-motion experience.

Request you can copy

Outcome: Use or define CSS Nesting to make the visual experience clear and easy to use. User context: A button nests `&:hover`, `&:focus-visible`, and `@media (forced-colors: active)` inside `.button`. This keeps six state rules near the base rule. A review rejects three levels of child selectors because they would tie the button to one page structure. Design concept to apply: CSS Nesting. Why it fits: Use one or two shallow levels for states, versions, and conditional at-rules that belong to the same component. Do not use it when: Avoid deep child chains and hidden ties to exact DOM structure. Native nesting does not always act like a CSS preprocessor. Design requirements: Set the content order, shared design values, and reusable components. Define how the layout changes by screen size and state. Keep useful design choices separate from decoration. Inclusion and resilience: Check contrast, zoom, languages, themes, and reduced motion when needed. Do not use color or effects as the only way to show meaning. Acceptance criteria: The design stays clear on phones and desktops, at zoom, in every theme, and in all supported languages. Interactive states stay clear and consistent. Evidence and limits (evidence boundary): A formal document may still be a draft, release candidate, or final version. Check its status and browser or platform support. Unknowns to confirm: Brand limits, amount of content, supported themes and languages, target devices, and design-system rules.

Check this request

Review the current use of CSS Nesting. Definition: CSS nesting is built-in syntax for writing one style rule inside another. The browser still follows CSS rules for reading selectors and their weight. Release checks: Check content order, shared design values, component consistency, contrast, zoom, and layout changes by screen size. Verify every theme, language, and state. If there is motion, offer an equal reduced-motion experience. Before changing code, report the evidence you found, gaps, severity, and the smallest safe fix.

A2
How official is this term?

Formal specification

A published, versioned formal specification defines this term for the listed technical scope.

A formal document may still be a draft, release candidate, or final version. Check its status and browser or platform support.

Scope
Nested CSS style rules
Document status
draft
Checked on
2026-07-30

Evidence sources & scope

Authority source + Term reference · W3C CSS Working Group · draft CSS Nesting Module Level 1 — Nesting style rules Nesting style rules Scope: Nested CSS style rules; direct scope: Nesting style rules Role here: Direct term reference Source covers: canonical name, definition, semantics, implementation Authority source · W3C CSS Working Group · draft CSS Nesting Module Level 1 Scope: Nested CSS style rules Role here: Authority within stated scope Source covers: canonical name, definition, semantics, implementation

Copy it yourself

The browser could not copy this. Select the request below and copy it yourself.