[csswg-drafts] [css-contain-3] Querying only the name of a container (#13093)

kizu has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-contain-3] Querying only the name of a container ==
With [container queries](https://drafts.csswg.org/css-conditional-5/#container-rule), we can have [named containers](https://drafts.csswg.org/css-conditional-5/#container-name), and then we can use these names to _filter_ some queries. Here is a quote from the spec:

> The `container-name` property specifies a list of query container names. These names can be used by `@container` rules to filter which query containers are targeted.

However, what if we could use this name _on its own_, to query just the presence of some named container, without any associated queries? ([CodePen that is not working anywhere for now](https://codepen.io/kizu/pen/EaKazyE))

```HTML
<div class="container">
  <div class="element">Wouldn’t it be nice if I was light green?</div>
</div>
```
```CSS
.container {
  container-name: --container;
}

@container --container {
  .element {
    background: lightgreen;
  }  
}
```

I [wrote a blog post](https://blog.kizu.dev/named-container-presence-check/) where I describe how we can do it today with size container queries and style container queries, although in a rather hacky way. I sometimes wanted to be able to query just the presence of some container around my element, without any specifics.

I also noticed that in the current container query syntax, it already allows to have just the container name! But it doesn't do anything:

```CSS
@container <container-condition># {
  <block-contents>
}

<container-condition> = [ <container-name>? <container-query>? ]!
```

So, unless there are reasons not to do this, I propose to explicitly allow only the `container-name` in the container query, and make it match if there is any named container with that name anywhere around the target element.


Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/13093 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 11 November 2025 20:45:14 UTC