query-feature

Style() — CSS reference

style() tests computed style values on a selected ancestor. Custom property equality queries let a component adapt to a semantic variant without a size containment context. Ordinary property queries are not established by this test.

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>style()</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