liveBook · Manning

@container

The @container at-rule conditionally applies CSS styles based on size or other features of an explicitly designated ancestor query container.

How 2 Manning books explain it

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.

Read how CSS in Depth, Second Edition explains @container →

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.

Read how Vanilla Web explains @container →

What to know first

Related concepts

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.