Repository navigation
Description
Description
Cascade Layers provides a powerful way to architect CSS code into “layers”, where the specificity of each layer is calculated independently of other layers — and where the web developer can define which layer will override which.
Specification
Cascade 5
Tests
Current tests
Rationale
Web developers often complain about CSS as a whole, especially about the CSS cascade. They increasingly inline all their CSS via JS, or use a framework of flat classes to style everything. Developers avoid using ID or element selectors, argue about !important, and basically try to avoid the CSS Cascade altogether. Cascade layers is recent effort by the CSSWG to fix these pain points for web developers by giving developers more powerful tools to handle complex modern websites. The idea is to lean into a more powerful cascade, instead of avoiding it.
Cascade Layers allows developers to create separate “layers” in their cascade — where everything in one layer will “beat” everything in another layer, no matter what the specificity of the code inside each layer. It builds on the way CSS Origins have always worked (where UA styles, User styles, and Author styles have all lived in separate origins – or layers — where specificity is calculated separately).
From the Cascade 5 Specification where Layers is defined:
Authors can create layers to represent element defaults, third-party libraries, themes, components, overrides, and other styling concerns—and are able to re-order the cascade of layers in an explicit way, without altering selectors or specificity within each layer, or relying on source-order to resolve conflicts across layers.
This is a powerful tool for re-architecting how a project’s CSS is structured that will not be useful until it’s in all browsers. Cascade Layers cannot be progressively enhanced or polyfilled client-side.
It’s also an example of a technology that’s well underway — all three engines have implementations behind a flag in preview browsers.
- Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1095765
- Gecko: https://bugzilla.mozilla.org/show_bug.cgi?id=1699214
- WebKit: https://bugs.webkit.org/show_bug.cgi?id=220779
- Working Draft: https://www.w3.org/TR/css-cascade-5/#layering
- Editor's Draft: https://drafts4.csswg.org/css-cascade-5/#layering
Cascade Layers will benefit from being included in Interop 2022, where extra attention to cross-browser testing will make sure the implementations are thoroughly interoperable.
Activity
jgraham commentedon Nov 5, 2021
Apologies, I just added an issue template for porposals, which I should have done much earlier.
Would you be able to rewrite the issue description to match that template?
gsnedders commentedon Nov 15, 2021
Tests: https://wpt.fyi/results/css/css-cascade?label=master&product=chrome%5Bexperimental%5D&product=firefox%5Bexperimental%5D&product=safari%5Bstable%5D&product=webkitgtk%5Bexperimental%5D&aligned&q=layer has a variety
@anttijk @xiaochengh given the ongoing implementation in both WebKit and Blink where these seem to come from, what's the coverage like? AIUI it's good?
xiaochengh commentedon Nov 15, 2021
The test coverage looks good to me, other than below:
xiaochengh commentedon Nov 23, 2021
The CSSOM API has just been specified: https://drafts.csswg.org/css-cascade-5/#layer-apis
I'll add tests to cover it.
xiaochengh commentedon Dec 7, 2021
CSSOM API tests have been added.
Also w3c/csswg-drafts#6323 has been resolved as rejected. So I think the test coverage is complete.
foolip commentedon Dec 7, 2021
Thanks @xiaochengh! I think web-platform-tests/wpt#31726 + web-platform-tests/wpt#31823 are the PRs that added the tests, and that it's these two tests:
Is that right?
xiaochengh commentedon Dec 7, 2021
Exactly!
foolip commentedon Jan 10, 2022
A proposed list of tests has been labeled with
interop-2022-cascade. It would be great if someone from each browser engine team can look over this list and comment if there are any issues.xiaochengh commentedon Jan 18, 2022
My comments regarding the list:
css/css-cascade/idlharness.htmlshould be includedlayer-stylesheet-sharing.htmlandlayer-stylesheet-sharing-important.htmlare less significant tests, because they test a specific edge case where the same stylesheet is inserted into a tree scope for multiple times. I don't see any real use case of doing itlayer-property-override.html,layer-counter-style-override.htmlandlayer-scroll-timeline-override.htmlare also less significant tests, because they test that@layercan reorder@property,@counter-styleand@scroll-timelinerules. Not all browsers support these at rules, and also their usages are much lower (all <1%) compared to@font-face(70%+) and@keyframes(80%+) according to chromestatus.comOther tests look good to me.
gsnedders commentedon Jan 21, 2022
These pass everywhere so I don't see much reason to exclude them, may as demonstrate the edge cases are interoperable.
We should either: simply remove these from interop2022, or make them pass with
assert_implements_optionalwhen the other at-rules aren't supported. Probably the former?Loirooriol commentedon Jan 21, 2022
Additionally to the tests mentioned by Xiaocheng,
revert-layer-011.htmlalso depends on@property.The last case in
layer-statement-before-import.htmldepends on constructable stylesheets, but other cases seem relevant so I would keep this one in interop-2022-cascade.anttijk commentedon Jan 25, 2022
layer-cssom-order-reverse.htmlalso contains a@propertysubtest. It would be nice if that was separate and excluded.Remove interop-2022-cascade from tests with new at-rules
gsnedders commentedon Feb 1, 2022
I've removed the tests in web-platform-tests/wpt-metadata#2492; this doesn't do anything about those with subtests though.