Keith's avatar
Keith J. Grant

I think we're going to regret CSS nesting, at least the way it’s defined in the spec.

CSS has been going in a very strong direction for the past five years. There just aren’t any more “gotchas” or confusing/misleading parts of modern CSS, because the W3C has worked their asses off essentially refactoring them all away... except nesting.

I think the sheer number of articles and posts coming out about “the gotchas of CSS nesting” should be a significant indicator to us that they got this one wrong. And I think we’re going to regret it in five years.

Right now, when Sass is still very familiar to us, we collectively seem to be okay with the problems of nesting, simply because it feels familiar. But I think, years from now, when we’ve long since stopped using Sass, nesting is going to end up that list of “Mistakes in the CSS spec.”

The W3C has done some phenominal work lately, but I’m disappointed they listened to those developer polls on this one. They should have gone with one of the less familiar but more predictable and consistent alternative syntaxes.

Link copied!
  1. avatar image

    @keithjgrant Counterpoint: most of the 'gotchas' are just differences from Sass. So in the future where Sass is no longer familiar to us, those behaviors are no longer 'gotchas' - just part of the feature.

    Especially with the recent resolution to support lookahead, so that the symbol-start requirement can be removed: https://github.com/w3c/csswg-drafts/issues/7961#issuecomment-1514955984

    [css-nesting-1] Can we relax the syntax further? · Issue #7961 · w3c/csswg-drafts
  2. avatar image

    @mia oh, I missed that that got resolved for level 1 of the spec! Nice! I wonder if any browsers have implemented that change yet

  3. avatar image
  4. avatar image

    @keithjgrant nearly all the gotchas aren't relevant if folks start nesting with &, since it takes out the majority of ambiguity and tricky moments

    imo, nesting isnt a mistake, it's the rush to remove requiring &..

Shared by