concept

Query container selection — CSS reference

Selection starts with the candidate element and finds the nearest eligible ancestor, filtered by name if supplied. The selected ancestor is used for the entire condition; the engine does not search farther simply because the condition is false. Naming can intentionally bypass an inner container with a different name.

Formal Syntax & Structure

css syntaxcss
@container card (width >= 200px) { ... }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>query-container-selection</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}#outer{width:300px;container:card / inline-size}#box{width:100px;container:inner / inline-size}@container (width >= 200px){#a{background:red}}@container card (width >= 200px){#a{color:rgb(0,100,0)}}</style><body><section id="outer"><section id="box"><div id="a">Component</div></section></section></body></html>
CSS Reference