concept

container-query-units — CSS reference

Container-relative lengths let a component scale to its surroundings rather than the entire page. Each required axis is resolved against its nearest eligible ancestor independently. An inline-size container may satisfy cqi without satisfying cqb; an outer size container may provide the latter. A cqmin or cqmax calculation can therefore combine two ancestors. Without an eligible ancestor the corresponding small viewport dimension is used. Inherited ordinary property values are already computed, not recalculated as the original unit on each descendant. A named @container condition does not itself bind all cq units to the named container.

Formal Syntax & Structure

css syntaxcss
container-type: inline-size; /* ancestor */width: 20cqi; /* descendant */

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>Relative length lab</title><style>body {margin:0} .sample {height:12px;background:#006050}#outer {container-type:size;width:300px;height:200px} #inner {container-type:inline-size;width:120px} #a {width:10cqi} #b {width:10cqb} #c {width:10cqmin} #d {width:10cqmax}</style><body><section id="outer"><div id="inner"><div id="a" class="sample"></div><div id="b" class="sample"></div><div id="c" class="sample"></div><div id="d" class="sample"></div></div></section></body></html>
CSS Reference