Skip to content

Declarative CSS Modules - <script> vs <style> for defining modules #10710

Open
@KurtCattiSchmidt

Description

@KurtCattiSchmidt

What is the issue with the HTML Standard?

This topic is for discussion of #10673, which is a Stage 1 proposal.

Our original explainer (MSEdgeExplainers/ShadowDOM/explainer.md at main · MicrosoftEdge/MSEdgeExplainers) uses <script> tags to define Declarative CSS Modules, but consensus seems to be overwhelmingly in favor of using a <style> tag instead.

Specifically, this example:

<script type="css-module" specifier="/foo.css"> 
  #content { 
    color: red; 
  } 
</script>

Would change to this:

<style type="module" specifier="/foo.css"> 
  #content { 
    color: red; 
  } 
</style>

The type="module" attribute is necessary to prevent styles from applying to the main document by default (this was one of the reasons for using the <script> tag initially).

The HTML5 Specification explicitly only allows <script> tags to have a type attribute of either:

  1. No type attribute
  2. type="text/css"

See https://html.spec.whatwg.org/#update-a-style-block - this will need to be amended to include a stage for Declarative CSS Modules.

Pros for the <script> approach

  1. Alignment with HTML modules

Pros for the <style> approach

  1. Developer familiarity
  2. Tooling compatibility (e.g. syntax highlighting)

The TPAC breakout session had quite a bit of discussion on this.

The MSEdgeExplainer's GitHub also had a public comment advocating for <style> over <script> - MicrosoftEdge/MSEdgeExplainers#887 (comment)

My preference is to proceed with updating the explainer to use <style> instead of <script> unless there are any objections.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions