Skip to content

Cascade Layers #5

Closed
Closed

Description

@jensimmons

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.

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

  1. jgraham commented on Nov 5, 2021

    @jgraham
    Contributor

    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?

  2. gsnedders commented on Nov 15, 2021

    @gsnedders
    Member
  3. xiaochengh commented on Nov 15, 2021

    @xiaochengh

    The test coverage looks good to me, other than below:

  4. xiaochengh commented on Nov 23, 2021

    @xiaochengh
  5. xiaochengh commented on Dec 7, 2021

    @xiaochengh

    CSSOM API tests have been added.

    Also w3c/csswg-drafts#6323 has been resolved as rejected. So I think the test coverage is complete.

  6. foolip commented on Dec 7, 2021

    @foolip
    Member

    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?

  7. xiaochengh commented on Dec 7, 2021

    @xiaochengh

    Exactly!

  8. added
    accepted
    on Dec 14, 2021
  9. foolip commented on Jan 10, 2022

    @foolip
    Member

    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.

  10. xiaochengh commented on Jan 18, 2022

    @xiaochengh

    My comments regarding the list:

    • css/css-cascade/idlharness.html should be included
    • layer-stylesheet-sharing.html and layer-stylesheet-sharing-important.html are 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 it
    • layer-property-override.html, layer-counter-style-override.html and layer-scroll-timeline-override.html are also less significant tests, because they test that @layer can reorder @property, @counter-style and @scroll-timeline rules. 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.com

    Other tests look good to me.

  11. gsnedders commented on Jan 21, 2022

    @gsnedders
    Member
    • layer-stylesheet-sharing.html and layer-stylesheet-sharing-important.html are 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 it

    These pass everywhere so I don't see much reason to exclude them, may as demonstrate the edge cases are interoperable.

    • layer-property-override.html, layer-counter-style-override.html and layer-scroll-timeline-override.html are also less significant tests, because they test that @layer can reorder @property, @counter-style and @scroll-timeline rules. 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.com

    We should either: simply remove these from interop2022, or make them pass with assert_implements_optional when the other at-rules aren't supported. Probably the former?

  12. Loirooriol commented on Jan 21, 2022

    @Loirooriol

    Additionally to the tests mentioned by Xiaocheng, revert-layer-011.html also depends on @property.

    The last case in layer-statement-before-import.html depends on constructable stylesheets, but other cases seem relevant so I would keep this one in interop-2022-cascade.

  13. anttijk commented on Jan 25, 2022

    @anttijk

    layer-cssom-order-reverse.html also contains a @property subtest. It would be nice if that was separate and excluded.

  14. gsnedders commented on Feb 1, 2022

    @gsnedders
    Member

    I've removed the tests in web-platform-tests/wpt-metadata#2492; this doesn't do anything about those with subtests though.

  15. added
    focus-area-proposal
    and removed on Sep 16, 2022
  16. added this to the Interop 2022 milestone on Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedfocus-area-proposal

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions