Nesting means writing one style rule inside another. Sass combines the outer selector with the inner one—by default with a descendant combinator (a space)—so you avoid repeating parents.
Official sample idea.
nav { ul { ... } } compiles to nav ul { ... }.
Mirrors HTML hierarchy.
Nesting is great for reading structure—nav → ul / li / a—without copying nav on every line.
Keep nests shallow.
Deep nesting generates long selectors that cost bandwidth and make overrides harder. Prefer about two or three levels.
Syntax
Syntax
SCSS
// Default: descendant join (a space)
nav {
ul { margin: 0; } // => nav ul
a { display: block; } // => nav a
}
// Selector lists expand pairwise
.alert, .warning {
ul, p { ... } // => .alert ul, .alert p, .warning ul, .warning p
}
// Combinators on outer, inner, or alone
ul > { li { ... } } // => ul > li
h2 { + p { ... } } // => h2 + p
// Need &:hover / &.is-active? See parent selector &
Pattern: open an outer rule → nest related children → Sass writes the combined CSS selectors.
Reference
Lists & Combinators
How nesting expands beyond a single pair:
Pattern
Result idea
Plain nest
nav { ul } → nav ul
Selector lists
Each side expands, then commas recombine
> / + / ~
Combinator can sit on outer, inner, or between
Parent &
For pseudo-classes and more—not a plain space join
Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).
Example 1 — Official Nav Nesting
Nest ul, li, and a under nav.
SCSS
nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
li { display: inline-block; }
a {
display: block;
padding: 6px 12px;
text-decoration: none;
}
}
Compiled CSS
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
}
nav a {
display: block;
padding: 6px 12px;
text-decoration: none;
}
How It Works
Outernav wraps related children.
Each nest becomes a descendant selector.
No repeatednav in the SCSS source.
Matches the official Sass docs sample.
Example 2 — Selector Lists
Comma-separated selectors nest pairwise, then recombine.
One line: nest style rules to combine selectors—keep depth low and reach for & when a plain space is not enough.
Practice
Compile Notes
Practical checklist:
checklist.txt
1. Nest related selectors under one parent
2. Expect a descendant join unless you add a combinator or &
3. Expand lists carefully (N × M selectors)
4. Prefer 2–3 levels of nesting
5. Use & for :hover, .is-active, and similar
Frequently Asked Questions
Nesting means writing one style rule inside another. Sass automatically combines the outer selector with the inner one (usually with a space), so you can mirror HTML structure without repeating parent selectors.
It becomes nav ul { } in CSS. The inner ul is nested under nav, so Sass joins them as a descendant selector.
Deep nests produce long selectors that are harder to override, larger to download, and slower for browsers to match. Prefer two or three levels for most UI, not five or six.
Each complex selector between commas nests separately, then Sass recombines them. .alert, .warning { ul, p { } } becomes .alert ul, .alert p, .warning ul, .warning p.
Yes. Put the combinator on the outer selector (ul > { li { } }), on the inner selector (h2 { + p { } }), or alone between them (p { ~ { span { } } }).
Use & when you need more than a plain descendant join—for example &:hover, &.is-active, or [dir=rtl] &. See the Sass Parent Selector page for details.