An element can be established as a query container for container size queries using the container-type
CSS property. container-type
is used to define the type of size containment used in a container query.
Size containment turns off the ability of an element to get size information from its contents, which is important for container queries to avoid infinite loops. If this were not the case, a CSS rule inside a container query could change the content size, which in turn could make the query evaluate to false and change the parent element's size, which in turn could change the content size and flip the query back to true, and so on.
The container size has to be set explicitly or by context — for example, block elements, flex containers, and grid containers stretching to the full width of their parent. If an explicit or contextual size is not available, elements with size containment will collapse.
Note: When using the container-type
and container-name
properties, the style
and layout
values of the contain
property are automatically applied.