Repository navigation
Description
Description
CSS Module Scripts are an already accepted web standard building on top of Import Attributes / Assertions and Constructable Stylesheets.
With CSS Module Scripts, at least for first party Web Components, developers would have a standards compatible way to not only import CSS into their Web Components, but also to share styles across the Shadow and Light DOM.
I made a little demo repo you can check out and hosted here (Vercel), which showcases a custom element importing a global "theme.css" in addition to its own component styles, highlighting the style sharing opportunities between light and shadow DOM.
import themeSheet from './theme.css' with { type: 'css' };
import componentSheet from './component.css' with { type: 'css' };
const template = document.createElement('template');
template.innerHTML = `
<h2>This should be blue and centered (theme.css)</h2>
<h3>This should be red and centered (component.css)</h3>
`;
export default class SomeComponent extends HTMLElement {
connectedCallback() {
if (!this.shadowRoot) {
this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
this.shadowRoot.adoptedStyleSheets = [themeSheet, componentSheet];
}
}
customElements.define('some-component', SomeComponent);<!DOCTYPE html>
<html>
<head>
<title>CSS Module Scripts Demo</title>
<script type="module" src="./some-component.js"></script>
<script type="module" src="./some-other-component.js"></script>
<link rel="stylesheet" href="./theme.css"/>
</head>
<body>
<h1>CSS Module Scripts Demo</h1>
<some-component></some-component>
<some-other-component></some-other-component>
</body>
</html>I think advancing CSS Module Scripts would be an extremely valuable addition to the platform across all browsers, as managing CSS otherwise is often a pain point, either requiring some sort of build tooling to inline CSS into <style> tags within the <template> of the Shadow Root or some other form of scripting to "adopt" <link> tags into adoptedStyleSheets.
Specification
WHATWG
Additional Signals
CSS Module Scripts and already implemented in Chrome, and have positive positions from both Webkit and Firefox.
This feature has been highly requested in prior interops
Here is a standalone issue for Import Attributes - #733
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
thescientist13 commentedon Sep 17, 2024
Would also add that investing in bringing Import Attributes to baseline would also help unlock #705 in tandem 🔗
gsnedders commentedon Sep 17, 2024
This is something like https://wpt.fyi/results/html/semantics/scripting-1/the-script-element?label=master&label=experimental&aligned&q=%28import-attributes%20or%20css-module%29%20and%20not%20assertions
thescientist13 commentedon Oct 8, 2024
Import Attributes are now stage 4! - #733 (comment)
wpt-interop commentedon Feb 13, 2025
Thank you for proposing CSS Module Scripts for inclusion in Interop 2025.
We wanted to let you know that this proposal was not selected to be part of Interop this year.
On behalf of the entire Interop team, thank you for submitting this proposal 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.
For an overview of our process, see proposal selection. Thank you again for contributing to Interop 2025.
Posted on behalf of the Interop team.
foolip commentedon Feb 20, 2025
Interop 2025 launched last week and I've been going through comments and reactions on proposals and then closing them. I see there are som 😕 reactions here, so I understand the outcome isn't what you had hoped for.
I think the proposal was clearly scoped so if you want to submit it again in the future there isn't anything that needs improving. I did go and look for the tests and associated them with web-features. This means you'll be able to follow any progress at https://webstatus.dev/features/css-modules (not a part of the Interop program!) and this link should work soon to list all tests:
https://wpt.fyi/results/?label=master&label=experimental&aligned&q=feature%3Acss-modules
I'll go ahead and close the issue now, and thank you again for proposing it!
justinfagnani commentedon Sep 4, 2025
Can we re-submit this for Interop 2026?
Firefox is landing their implementation as we speak, which would make it two major engines that support native CSS Modules. Seems very useful to include this for WebKit at least.
jgraham commentedon Sep 4, 2025
You are welcome to resubmit any previous proposals that you still think meet the appropriate criteria for Interop 2026. You just need to open a new issue with the relevant (up to date) details about the proposal.