CKTIS / CSS
Selector nesting and the & selector
Native CSS nesting allows rules inside rules. The & selector refers to the elements matched by the parent rule.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
.card {
&.active { color: green; }
& > .label { font-weight: bold; }
}Inside a nested rule, & represents elements matched by the parent selector. &.active targets the same element, whereas & .active targets its descendants. > .label means the same as & > .label; .label alone selects descendants by default.
The specificity of & is the highest specificity in the parent's selector list, like :is(), regardless of the matching branch. Nesting is not text concatenation: &--active is invalid. & cannot represent pseudo-elements.
The example makes the card green and its direct label bold. Expected console messages are provided separately; the example requires local verification.
Examples
<!doctype html>
<meta charset="utf-8">
<title>CSS nesting</title>
<style>
.card {
color: black;
&.active { color: green; }
& > .label { font-weight: 700; }
}
</style>
<div class="card active"><span class="label">Ready</span></div>
<script>
const card = document.querySelector('.card');
const label = document.querySelector('.label');
console.log(getComputedStyle(card).color);
console.log(getComputedStyle(label).fontWeight);
</script>Result
rgb(0, 128, 0) 700
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.