Skip to content

[css-contain-3] Can we allow custom properties in dimensional container queries? #8088

@mirisuzanne

Description

@mirisuzanne

Currently, dimensional queries allow relative units and resolve those units on the container:

html {
  container: root / inline-size; 
  font-size: 32px;
}

/* 32px em size, equivalent to (inline-size > 960px) */
@container root (inline-size > 30em) { ... }

Style queries (according to the spec) currently compare computed values - which means they also resolve custom properties in the query condition (again, using the container as context for the resolution):

/* true in a theme container using the background color 
    that matches the value of `--bg-dark` on that same container */
@container theme style(background-color: var(--bg-dark)) { … }

It would be great if we're able to do something similar for dimensional queries:

/* true in a container with inline-size greater than
    the value of `--small-container` on that same container */
@container (inline-size > var(--small-container)) { … }

This has been a highly-requested feature in media queries, but it seems like container queries should actually make it possible - since we have an element that we can use as context for resolving the custom property.

What would it take to specify that? Would we need to know in advance that the variable has the right type, e.g. requiring @property to define the custom property as a <number>? Are there other approaches we should consider, that wouldn't rely on @property?

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions