Original posted in #7834
To organize the discussion a bit, the options we're looking at are:
& or by being an @nest rule. If not using @nest, every selector in a list needs to start with &, not just the first.@nest; rule we'd introduce.&. (Rules following the switch can start with whatever.).foo, :hover, etc will trigger the switch, but div won't.) (Rules following the switch can start with whatever.)& 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.)& needed in nested selectors except for disambiguation. Style rules effectively consist of a selector, a declaration block, and an optional style rule block.
@nest rule&&) to indicate association of nested rules with the previous selector@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:
| # | Pros | Cons |
|---|---|---|
| (1) |
|
|
| (2.i) |
|
|
| (2.ii) |
|
|
| (2.iii) |
|
|
| (3) |
|
|
| (4) |
|
|
| (5) |
|
|
(Percentages normalized to exclude "Just show results" answers)
Which of the following best expresses how you want to write nested CSS when it's implemented by browsers?
& in every selector, as I think it makes code more clear& whenever possible, as it's noisy to read and a hassle to typeIf it were up to you, what syntax would you prefer for CSS Nesting?
& should be mandatory, even in descendants and combinators& should be optional for descendants and combinatorsAdd 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.
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 |