Native CSS Nesting (No Sass or Less)
Nesting selectors without Sass or Less
Selector nesting was the #1 reason people reached for Sass. It's now built into CSS and part of Baseline 2023. Same & syntax, zero build tools.
The old hack vs the modern fix
View demo// nav.scss, requires Sass compiler
.nav {
display: flex;
gap: 8px;
& a {
color: blue;
}
}/* nav.css, plain CSS, no compiler */
.nav {
display: flex;
gap: 8px;
& a {
color: #888;
text-decoration: none;
&:hover {
color: white;
}
}
}Nesting browser support
Live demo
Why the modern way wins
No build step
Drop Sass, Less, PostCSS, or any compiler. Ship CSS directly to the browser, nesting included.
Familiar syntax
The & works much like it does in Sass, so the learning curve is small. Unlike Sass, & can't be joined to make new class names like &__title.
Smaller toolchain
One fewer dependency in your build. Faster installs, simpler CI, fewer things to break.
- Dependency Removed
- Sass / Less
- Build tool eliminated
- Old Approach
- .scss → .css
- Compile step required
- Modern Approach
- .css → .css
- Ship as-is
How it works
CSS nesting lets you write child selectors inside parent rule blocks using the & symbol, just like Sass. The browser interprets .nav { & a { ... } } as .nav a { ... }.
You can nest pseudo-classes (&:hover), pseudo-elements (&::before), and even media/container queries inside a rule block. The & always refers to the parent selector.
Unlike the initial release, the relaxed nesting syntax lets you write bare element selectors like a { color: red } directly inside a parent. The & is only required for compound selectors like &:hover or &.active. Two differences from Sass remain. & can't be joined to make new class names (&__title), and it acts like :is(), which can change specificity.