Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: CSS @sheet #11509

Open
KurtCattiSchmidt opened this issue Jan 15, 2025 · 1 comment
Open

Proposal: CSS @sheet #11509

KurtCattiSchmidt opened this issue Jan 15, 2025 · 1 comment

Comments

@KurtCattiSchmidt
Copy link

Link to explainer

CSS @sheet is a mechanism for bundling multiple CSS stylesheets into one .css file. There are numerous practical advantages to bundling multiple CSS sheets into one file, including reduced network requests and potentially increased compression ratios.

@sheet is an at-block with an identifier:

style.css:

@sheet sheet1 {
 ...
}

Sheets defined via @sheet can be referenced via fragment identifiers in URL's that match the @sheet identifier:

<link rel="stylesheet" href="style.css#sheet1">

This was discussed in the CSSWG call on 2023-04-05 as well as this discussion.

We propose expanding this definition to include @sheet definitions at the document level, which can similarly be referenced via a local fragment:

<style>
@sheet sheet1 {
 ...
}
</style>
<link rel="stylesheet" href="#sheet1">

Much like anchor fragments, Shadow DOM nodes can access @sheet definitions from their parent scope:

<style>
@sheet foo {
  div {
    color: red;
  }
}
</style>
<template shadowrootmode="open">
  <link rel="stylesheet" href="#foo" />
  <span>I'm in the shadow DOM</span>
</template>

More details and examples can be found in the explainer link above. I would welcome any comments/suggestions/additional use cases, either in this thread or as issues in the MSEdgeExplainers repo: New issue

@jyasskin
Copy link
Member

jyasskin commented Jan 18, 2025

FWIW, a fragment pointing into an HTML file seems like the wrong way to refer to @sheet declarations inside inline CSS inside that HTML file. Specifically, fragment resolution in URLs depends on the MIME type of the resource (https://html.spec.whatwg.org/multipage/browsing-the-web.html#the-indicated-part-of-the-document, https://www.rfc-editor.org/rfc/rfc8820#name-uri-fragment-identifiers). Inside an HTML document, fragments point to the element with a matching 'id' or <a name> attribute, or the text identified by https://wicg.github.io/scroll-to-text-fragment/#invoking-text-directives. That won't find an @sheet.

You could consider extending the fragment syntax again to allow it to explicitly navigate into inline CSS, but I feel like a new attribute might be a better way to do this, as discussed in w3ctag/design-reviews#1000 (comment).

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

No branches or pull requests

3 participants