Summary of Nesting proposals

Original posted in #7834

To organize the discussion a bit, the options we're looking at are:

  1. Current spec - every nested rule needs to be unambiguous on its own, either by starting with an & or by being an @nest rule. If not using @nest, every selector in a list needs to start with &, not just the first.
  2. Parser switch proposal - after some parsing switch has been tripped, everything's assumed to be a nested rule. There are a few possibilities for the parsing switch:
    1. Just at-rules. This means any nested at-rule, like a nested @media, or the no-op @nest; rule we'd introduce.
    2. (link) The above, plus any style rule starting with an &. (Rules following the switch can start with whatever.)
    3. (link) The above, plus any style rule starting with a non-ident. (So .foo, :hover, etc will trigger the switch, but div won't.) (Rules following the switch can start with whatever.)
  3. Non-letter start proposal - No parsing switch, instead every nested rule has to be unambiguous on its own, by starting with anything but an ident. (You can write & div or :is(div) if you need to start a selector with a type selector.) (This employs the same parsing strategy as (2.iii) to avoid accidentally parsing invalid properties like //color: red; as rules.)
  4. Postfix proposal - Block after main rule containing nested rules, no & needed in nested selectors except for disambiguation. Style rules effectively consist of a selector, a declaration block, and an optional style rule block.
    1. Could add the rule block with an @nest rule
    2. Could add the rule block with special ASCII selector (e.g. &&) to indicate association of nested rules with the previous selector
    3. Could add the rule block with bare braces, essentially giving the selector prelude associated two blocks (one declaration block, one optional rule block).
  5. Top-level nesting container - Top-level @nest rule having one or more selectors and a block of nested rules, no & needed in nested selectors except for attaching psuedos to the parent selector. No mixing of properties and rules.

Arguments for each of the above options:

Twitter Polls

(Percentages normalized to exclude "Just show results" answers)

Poll 1: What do authors prefer for their own code (1,613 votes)

Which of the following best expresses how you want to write nested CSS when it's implemented by browsers?

Poll 2: What do authors want to be the general rule (592 votes)

If it were up to you, what syntax would you prefer for CSS Nesting?

Discussion Participant Positions

Add your name and preferred proposals below:

Participant Top choice Runner-up Third choice
fantasai 3 or 4.ii or 4.iii 2.ii or 2.iii
LeaVerou 3 2.iii 2.ii
tabatkins 3 1 2.iii
Loirooriol 1 4.i or 4.iii 2.i or 3
argyleink 1 3 4
bradkemper 2.iii 2.ii 3
mirisuzanne 3 2.iii 4
romainmenke 1 3 4
FremyCompany 4.iii 1 3
dbaron 4.iii 3 * 1
alohci 3 1 4
svgeesus 3 2.iii
bramus 3 1 2.iii
jonathantneal 3 * 1
sesse 1 3
lilles 1 3
ydaniv 4.iii or 4.ii 1 3
andruud 3 1 4
valtlai 3 1 2.iii
jensimmons 4 3
rossen 4 3 1
flackr 3 1 2.iii
JakeA 1 3

Note: It is not required to be a WG member to add your name to this list, only to have followed the discussion and considered the proposals (summarized above) carefully.

Note: Proposal 5 was not considered in this poll.

Counts

23 participants voted.

Proposal Top choice votes Runner-up votes Third choice votes
1 6 9 2
2 (all) 1 6 5
2.i 0 0 1
2.ii 0 2 1
2.iii 1 4 4
3 12 7 4
4 (all) 5 2 5
4.i 0 1 0
4.ii 2 0 0
4.iii 3 1 0