Skip to content

[css-conditional-5] Add container() as a leaf of the @when rule #6917

@bramus

Description

@bramus

It would be nice to also see a container() function as a leaf of the @when rule, in addition to the already specced media() and supports() functions.

The syntax would preferably be the same as the @​container rule:

container() = container( [ <container-name> | [ name(<container-name>) || type(<container-type>+) ] ]? <container-query> )

(Perhaps the optional part should not be optional here, for performance reasons? 🤔)

Use case: it would allow stuff such as easy dark mode toggling based on the value of a custom property on a style container:

@when media(prefers-color-scheme: dark) or container(root style(--color-scheme = dark)) {
  body {
    --primary-color: #efefef;
    --primary-bg-color: #333;
  }
}

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