[css-cascade] Should unnamed cascade layers be allowed? · Issue #5792 · w3c/csswg-drafts (original) (raw)

The draft Cascade 5 specification allows anonymous/unnamed cascade layers.

While these layers behave exactly like named layers in every way, they do not provide a "hook" for merging or re-ordering @layer rules. In most use-cases this would only be syntax-sugar for brevity -- relying on well-organized source-order rather than any explicit names. However, it could be used by teams as a way to "force" an organizing convention (all layer code must be defined in one place), or by libraries wanting to merge & hide a set of internal "private" layers that they don't want exposed to author manipulation:

/* bootstrap-base.css / / unnamed wrapper layers around each sub-file */ @layer url(base-forms.css); @layer url(base-links.css); @layer url(base-headings.css);

/* bootstrap.css / / the intrnal names are hidden from access, subsumed in "base" */ @layer base url(bootstrap-base.css);

/* author.css / / author has access to bootstrap.base layer, but not into unnamed layers */ @layer bootstrap url(bootstrap.css);

I think that's a useful feature for providing more control to authors, but others have raised issues that it might be misused.