Skip to content

Module Stylesheet <link> tags - #12860

Open
KurtCattiSchmidt wants to merge 2 commits into
whatwg:mainfrom
KurtCattiSchmidt:link-module-import
Open

KurtCattiSchmidt wants to merge 2 commits into
whatwg:mainfrom
KurtCattiSchmidt:link-module-import

Conversation

@KurtCattiSchmidt

@KurtCattiSchmidt KurtCattiSchmidt commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Adds support for <link rel=stylesheet import=foo>, where the import attribute performs a module stylesheet import, equivalent to import("foo", { with: { type: "css" } } in Javascript.

(See WHATWG Working Mode: Changes for more details.)

Addresses #10673


/indices.html ( diff )
/links.html ( diff )
/semantics.html ( diff )
/webappapis.html ( diff )

@KurtCattiSchmidt KurtCattiSchmidt mentioned this pull request Aug 28, 2026
4 of 5 tasks
@KurtCattiSchmidt KurtCattiSchmidt added the agenda+ To be discussed at a triage meeting label Sep 9, 2026
@LeaVerou

LeaVerou commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

See #10673 (comment)

@KurtCattiSchmidt

Copy link
Copy Markdown
Contributor Author
  • Do we need <style type=module> as well?

@LeaVerou - this was discussed a few weeks ago at WHATNOT and added to the design doc. More details in this comment in the old PR. Please add more pros and cons to the design doc if you think of any that are missing.

This PR is no longer using type=module, see this comment in the old PR for more details.

  • There is nothing on how @import behaves in a module context. I'd imagine type=module should affect that (these should become part of the module graph and be fetched accordingly, just like <link type=module>).

One of the main goals of this proposal is parity with importing a CSS module via script. Any changes to the module graph would require changes to how @import works in existing CSS module script imports. So I don't believe any changes are necessary in this PR for CSS @import, but any future changes to @import in a module context would also apply here.

It would also be good to file for a TAG review on this, as it's a significant architectural change.

The existing existing TAG response also supported using <link> for this scenario.

@keithamus

keithamus commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

This was agendad for the 2026-09-17 meeting but we ran out of time so agenda+ To be discussed at a triage meeting should remain. We'll hopefully discuss next week.

@lukewarlow

Copy link
Copy Markdown
Member

It would be good to update OP if type="module" isn't being used anymore (it confused me initially)

@rniwa

rniwa commented Sep 24, 2026

Copy link
Copy Markdown

The latest proposal is:

<link type=text/css rel=stylesheet import=foo.css>

@jstenback jstenback removed the agenda+ To be discussed at a triage meeting label Sep 24, 2026
@KurtCattiSchmidt

KurtCattiSchmidt commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

The latest proposal is:

<link type=text/css rel=stylesheet import=foo.css>

To clarify, the type=text/css isn't necessary (it already exists for <link> and will reject anything that's not text/css when rel=stylesheet).

<link rel=stylesheet import=foo.css> is equivalent to what you listed @rniwa

@robglidden

Copy link
Copy Markdown

This was agendad for the 2026-09-17 meeting but we ran out of time so agenda+ To be discussed at a triage meeting should remain. We'll hopefully discuss next week.

I see this (PR 12860 Module Stylesheets Syntax) was indeed discussed at the WHATNOT meeting on 2026-09-24, see meeting notes.

I note that style module imports (i.e. the new <link rel=stylesheet import="foo.css"> proposal) are also mentioned in issue 12163 specifier: URL protocol for retrofitting specifiers in places designed for URLs.

@LeaVerou

LeaVerou commented Oct 8, 2026

Copy link
Copy Markdown
Member

The way JS solved this was type=module on <script> and a corresponding nomodule attribute for fallbacks etc, which also allows fallbacks that are different (in JS that was essential since the syntax is incompatible, but I can see it being useful here too). I don't think this pattern was considered, at least last time I looked at the doc.

@KurtCattiSchmidt

Copy link
Copy Markdown
Contributor Author

@LeaVerou - you're right, nomodule is a possibility here, and it's not covered in the explainer. With fallback, the two options would look like:

<link rel=stylesheet href=./styles/foo.css import=foo>

vs

<link rel=stylesheet type=module href=foo>
<link rel=stylesheet href=./styles/foo.css nomodule>

But we also have <link rel=modulepreload> that uses href that adds an entry to the module map and does not require type=module. So it really comes down to consistency between different types of<link>s vs consistency between <link> and <script>.

@noamr

noamr commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@LeaVerou - you're right, nomodule is a possibility here, and it's not covered in the explainer. With fallback, the two options would look like:

<link rel=stylesheet href=./styles/foo.css import=foo>

vs

<link rel=stylesheet type=module href=foo>
<link rel=stylesheet href=./styles/foo.css nomodule>

I think either is fine. Let's pick one and do this.


But we also have `<link rel=modulepreload>` that uses `href` [that adds an entry to the module map](https://html.spec.whatwg.org/#link-type-modulepreload) and does not require `type=module`. So it really comes down to consistency between different types of`<link>`s vs consistency between `<link>` and `<script>`.

I wouldn't worry too much about consistency with modulepreload. It's a performance optimization and it's OK that it's a URL and not a specifier.

@LeaVerou

LeaVerou commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

I agree with @noamr about modulepreload. But also, an import attribute isn't consistent with that either, modulepreload still uses href.

So it's about following one of two existing precedents vs creating a third 😅

FWIW I do think import might be a better design — I kinda wish <script> and modulepreload had gone that way as well. But given that they didn't, I don't think it passes the bar of being so much better as to warrant breaking consistency and introducing a third pattern.

That said, neither <script src> nor <link rel=modulepreload href> actually accept specifiers, only URLs, so perhaps that's the distinction that justifies an import attribute (and then we could also add it to the other two).

@noamr

noamr commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

That said, neither <script src> nor <link rel=modulepreload href> actually accept specifiers, only URLs, so perhaps that's the distinction that justifies an import attribute (and then we could also add it to the other two).

Also <script type=module> works without src, so it doesn't necessarily import.
But yes - that's the more important distinction... making href support something that's not a document-relative URL based on the type attribute is a bit awkward.

@myakura

myakura commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

I don't know if type="module"/nomodule pattern is a good fit for <link>:

  • Semantics of type on <link>: On <script>, type was overloaded for "module" and "importmap" because <script> has no rel attribute. On , rel defines the processing model while type is just an advisory MIME type hint (which is also why we have rel="modulepreload" rather than rel="preload" type="module").
  • Simpler fallback without nomodule: Because module stylesheets may use bare specifiers, using href with type="module" requires authoring two separate <link> elements with nomodule for fallback. With the proposed import attribute, a single <link rel="stylesheet" import="foo" href="fallback.css"> gracefully falls back to href in legacy browsers without needing nomodule at all.

@KurtCattiSchmidt

Copy link
Copy Markdown
Contributor Author

That said, neither <script src> nor actually accept specifiers, only URLs, so perhaps that's the distinction that justifies an import attribute (and then we could also add it to the other two).

@LeaVerou - yeah, the extensibility aspect on other elements is pretty great for import. Another other nice thing is that we could use export for declarative inline modules instead of specifier and there would be some nice symmetry.

@robglidden

Copy link
Copy Markdown

That said, neither <script src> nor actually accept specifiers, only URLs, so perhaps that's the distinction that justifies an import attribute (and then we could also add it to the other two).

@LeaVerou - yeah, the extensibility aspect on other elements is pretty great for import. Another other nice thing is that we could use export for declarative inline modules instead of specifier and there would be some nice symmetry.

import and export seem like a promising direction for multiple reasons, and to me seem more promising than retrofitting urls to specifiers or URLorSpecifers.

@hiroshige-g

Copy link
Copy Markdown
Contributor

cc/ @whatwg/modules

@sorvell

sorvell commented Oct 29, 2026 •

Copy link
Copy Markdown

Is FOUC addressed by this? If not, it seems very unlikely to be used in declarative Shadow DOM. It's likely also not acceptable unless explicitly specified.

I believe currently, blocking rendering only happens if the link is potentially render-blocking, and a document stops accepting render-blocking elements once <body> exists. So a <link import> inside a declarative shadow root in <body> never blocks rendering. Even when the specifier is already in the module map, setting the link’s sheet is queued as a task. So every instance after the first can paint unstyled.

@hiroshige-g

Copy link
Copy Markdown
Contributor

One thing I came up with just after the TPAC session:

The <link import> requests must be CORS-enforced to match with existing module maps / CSS modules.
So maybe on fallback (without import support), we should also CORS-enforce this.
So maybe we should enforce <link import crossorigin=anonymous> (i.e. fail if no crossorigin or crossorigin=use-credentials).

@noamr

noamr commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

One thing I came up with just after the TPAC session:

The <link import> requests must be CORS-enforced to match with existing module maps / CSS modules.
So maybe on fallback (without import support), we should also CORS-enforce this.
So maybe we should enforce <link import crossorigin=anonymous> (i.e. fail if no crossorigin or crossorigin=use-credentials).

But modules can fetch with use-credentials no?
Yes default importing is crossorigin=anonymous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.