Container queries

Container queries apply styles based on the size of the container rather than the screen. A component adapts the same way in a narrow sidebar as in a wide column.
  • container-type: inline-size: makes an ancestor queryable by its width.
  • container-name: assigns a name to query a specific container.
  • @container (min-width: ...): applies rules when the container reaches that size.
  • cqw / cqh: units relative to the container’s width and height, equivalent to vw and vh.

Example

Lower the container width control. The card switches from one column to two when its container exceeds 28rem, without any media query.

ResultLive
html
css