@container
The @container at-rule conditionally applies CSS styles based on size or other features of an explicitly designated ancestor query container.
CSS in Depth, Second Edition
A CSS container size query is a conditional query that evaluates the size of an explicitly defined ancestor query container.
- How it is used
- Adapts reusable modules to available ancestor width when viewport-based media queries produce cramped layouts.
- How deep it goes
- Works through container setup, query syntax, and named-ancestor selection; notes a sizing constraint without detailing its mechanics.
- Examples
- Uses a two-column page whose sidebar cramps a media module, then replaces its viewport breakpoint with a container-width breakpoint.
- What you can do after
- Build it from scratch by defining query containers and applying @container rules to responsive module layouts.
Vanilla Web
A container query is a CSS conditional rule that applies styles based on the size of an element's containing ancestor rather than the viewport.
- How it is used
- Makes reusable components respond to available ancestor space rather than a page-wide viewport breakpoint.
- How deep it goes
- Works through container declaration and a width-triggered card layout; mentions names, height queries, and container units without implementing them.
- Examples
- Uses identical cards in a main area and sidebar, with a 400px container threshold that switches to a two-column grid.
- What you can do after
- Build it from scratch by declaring a size container and adding conditional card styles that vary with placement.
What to know first
- flexboxFlexbox is a CSS one-dimensional layout model for arranging, sizing, aligning, and distributing items along a row or column.
- media queryA media query is a CSS conditional rule that applies styles when specified media types or presentation-environment features match.
- responsive designResponsive design is an approach to designing web interfaces whose layout and presentation adapt to different screen sizes, viewports, and device characteristics.
Related concepts
- media querycontrasts with · A media query is a CSS conditional rule that applies styles when specified media types or presentation-environment features match.
- containerused by · A software container is an isolated execution environment that packages an application and its dependencies, typically sharing the host operating-system kernel.
- container style queryincludes · A CSS style query conditionally applies styles based on the computed style values of a query container, including its custom properties.
- CSSused by · CSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- container-relative unituses · A container-relative unit is a CSS length unit whose value is calculated from the dimensions of a query container.
Questions about @container
What is @container?
The @container at-rule conditionally applies CSS styles based on size or other features of an explicitly designated ancestor query container.
Which Manning books explain @container?
CSS in Depth, Second Edition and Vanilla Web.
What should I know before learning @container?
Manning books that teach @container usually introduce flexbox, media query and responsive design first.
What is the difference between @container and media query?
The @container at-rule conditionally applies CSS styles based on size or other features of an explicitly designated ancestor query container. A media query is a CSS conditional rule that applies styles when specified media types or presentation-environment features match.
What kinds of @container are there?
Kinds of @container include container style query.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

