concept

Container style query — CSS reference

Style queries can use normal ancestors and do not need size containment. Set a custom property on a wrapper, then match its computed value to choose a descendant variant. This fixture tests custom-property equality only.

Formal Syntax & Structure

css syntaxcss
@container style(--variant: compact) { /* descendant styles */ }

Working Example

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