Skip to content

CSS Module Scripts #1056

Closed
Closed

Description

@jakelazaroff

Description

Allow importing CSS files from within JavaScript modules using import assertions and adoptedStyleSheets:

import sheet from './styles.css' with { type: 'css' };
document.adoptedStyleSheets = [sheet];
shadowRoot.adoptedStyleSheets = [sheet];

The cool thing is that this allows you to manipulate stylesheets with JavaScript before applying them. For example, @davatron5000 has a neat example of how to emulate CSS modules (the confusingly-similar non-standard name for scoping CSS by hashing class names) using CSS Module Scripts: https://daverupert.com/2021/08/css-modules-in-css-modules/

Specification

https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-css-module-script

web-feature

https://web-platform-dx.github.io/web-features-explorer/features/css-modules/

Test Links

https://wpt.fyi/results/html/semantics/scripting-1/the-script-element/css-module
https://github.com/web-platform-tests/wpt/tree/master/html/semantics/scripting-1/the-script-element/css-module

Additional Signals

https://bugzilla.mozilla.org/show_bug.cgi?id=1720570
https://bugs.webkit.org/show_bug.cgi?id=227967

Activity

  1. github-actions commented on Sep 9, 2025

    @github-actions

    This comment was automatically generated based on the information you provided. Please don't edit it.

    Below is additional information about the web feature (from the web-features project) which is referenced in your proposal.
    If this doesn't accurately correspond to your proposal, please update your initial comment to include web-features: <feature-id>.
    To find feature IDs, use the web-features explorer.

    Feature CSS import attributes

  2. o-t-w commented on Oct 1, 2025

    @o-t-w

    This feature is now available in Firefox Nightly:

    Starting with Firefox 145, support has been added for CSS module scripts, disabled by default using the preference layout.css.module-scripts.enabled.

  3. wpt-interop commented on Feb 12, 2026

    @wpt-interop
    Collaborator

    Thank you for proposing CSS Module Scripts for Interop 2026.

    We want to let you know it was not selected to be part of Interop this year.

    On behalf of the entire Interop team, thank you for submitting it for consideration. We got many more proposals than we could include in this year's project, necessitating some difficult choices. Please note this should not be taken as a comment on the technology as a whole, or our willingness to consider it for Interop in the future. We appreciate the work you put into your proposal, and would welcome your participation in future rounds of Interop.

    Posted on behalf of the Interop team.

  4. klebba commented on Mar 11, 2026

    @klebba

    (UGHHHHH. This is so disappointing. IS THERE NO HOPE FOR THE WEB!!??)

    The browser groundhog has seen its ShadowDOM again and doomed the web to another year of CSS-in-JS.

    If you found this thread and still fantasize about using encapsulated native stylesheets, consider politely nudging this issue with your interest: https://bugs.webkit.org/show_bug.cgi?id=227967

    Another idea: maybe @LeaVerou has the star power necessary to get this one over the finish line sooner?! If you're reading this, please help! I don't want to transpile my CSS any more!

  5. LeaVerou commented on Mar 12, 2026

    @LeaVerou
    Member

    (UGHHHHH. This is so disappointing. IS THERE NO HOPE FOR THE WEB!!??)

    The browser groundhog has seen its ShadowDOM again and doomed the web to another year of CSS-in-JS.

    If you found this thread and still fantasize about using encapsulated native stylesheets, consider politely nudging this issue with your interest: bugs.webkit.org/show_bug.cgi?id=227967

    Another idea: maybe @LeaVerou has the star power necessary to get this one over the finish line sooner?! If you're reading this, please help! I don't want to transpile my CSS any more!

    This may be a productive avenue: https://bsky.app/profile/lukewarlow.dev/post/3mguqlqozck23

  6. klebba commented on Mar 12, 2026

    @klebba

    Thank you!

    For reference, here are all Interop request/rejection threads for CSS Module Scripts:

    It would be great to see the Interop team reevaluate inclusion using cumulative and lasting community interest.

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

    focus-area-proposal

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions