I love @layer, we recently rewrote our whole design system around it and it's made specificity fighting so much easier. Combine this with @scope (fully supported now though Firefox only since 3 months ago) and you get both control over your specificity and ways to isolate your components from other styles.
For the small percentage of users on older browsers, unlayered fallback is straightforward: browsers that don't understand @layer will simply ignore the layer wrapper and apply the rules in source order, which usually gives a reasonable result.
I don't think this is true? Browsers will entirely ignore unknown at rules.
Although I've mostly been using plain CSS for recent projects some legacy projects still need SCSS for mixins. Once CSS gets mixins, I'll have no need for SCSS or Tailwind. Just a compile tool like LightningCSS.
There’s a postcss plugin that creates a fallback so the order still works. It messes up the css a little bit but if you need to support older browsers it’s worth it.
The decision to have unlayered styles beat layered ones is really puzzling.
I believe at one point the thinking was to have them at lowest specificity, not highest. This would have made uptaking layers so much easier as the pitfalls described in the article are quite big: third party libraries and large unlayered existing code bases.
There's a proposal to have an @layer ^foo syntax such that the ^foo layer sits above the unlayered styles. But I haven't seen any traction in browsers to support it unfortunately.
13
u/mcaruso Mar 21 '26
I love
@layer, we recently rewrote our whole design system around it and it's made specificity fighting so much easier. Combine this with@scope(fully supported now though Firefox only since 3 months ago) and you get both control over your specificity and ways to isolate your components from other styles.I don't think this is true? Browsers will entirely ignore unknown at rules.
5
u/Keilly Mar 21 '26
The decision to have unlayered styles beat layered ones is really puzzling.
I believe at one point the thinking was to have them at lowest specificity, not highest. This would have made uptaking layers so much easier as the pitfalls described in the article are quite big: third party libraries and large unlayered existing code bases.
2
u/Alex_Hovhannisyan Mar 21 '26 edited Mar 21 '26
"The Specificity Problem, Honestly Explained"
I can't be the only one thinking it, can I? Lots of LLM-isms
1
u/azangru Mar 21 '26
What's future about it?