Skip to content

CSS Module Scripts #206

@Westbrook

Description

@Westbrook

Description

CSS Module Scripts allow JavaScript modules to import style sheets. They can then be applied to a document or shadow root using adoptedStyleSheets in the same way as constructible style sheets.

Not currently available cross browser (Safari) effecting adoption.

Rationale

  • CSS modules will allow styles to be loaded in component definitions without adding <style> or elements that need to be created in each element instance.
  • Authors today often use inlined CSS strings in JS modules, but many of them want to move the CSS into separate .css files.
  • Without CSS-in-JS it's difficult to ensure that CSS is loaded before the component is defined and rendered. CSS module scripts provide the same ordering guarantee.
  • Component authors may need to import a resource that is only available as an external .css file, and don't have control over the resource to wrap it in a JS module.

Specification

https://github.com/tc39/proposal-import-assertions

Tests

tc39/test262@18834b2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions