Skip to content

[cssom] allow text in CSSStyleSheet constructor #12110

Open
@jonathantneal

Description

@jonathantneal

May we consider allowing CSSStyleSheetInit to accept a text property that synchronously assigns rules to the constructed sheet?

dictionary CSSStyleSheetInit {
  DOMString baseURL = null;
  (MediaList or DOMString) media = "";
  boolean disabled = false;
  DOMString text = "";
};

Example usage:

new CSSStyleSheet(":host{ /* styles */ }")

Example in adoptedStyleSheets:

shadowRoot.adoptedStyleSheets = [ new CSSStyleSheet(":host { /* styles */ }") ]

The goal is to improve the authoring experience for constructed stylesheets, especially within custom elements, by enabling inline creation without needing to call replaceSync() separately. This would be a small but meaningful ergonomic improvement and a low-barrier enhancement that could benefit many developers working with adoptedStyleSheets.

Would this be appropriate for inclusion in the spec, or is it better suited for discussion elsewhere?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions