← All notes

CSS container queries: style a child from its parent's size

Answer: Container queries allow adjustments to elements based on the size and state of their ancestors, or containers. You can define a container by using the container-type property. Container queries use the @container at-rule.

Queries against a container, not the viewport

Media queries still adjust a layout from viewport size or device type.

Container queries let you adjust elements based on the size and state of their ancestors, also called containers.

In the web.dev demo, font-size, padding, and layout follow the nearest container, not the viewport size.

Two steps to set one up

Unlike media queries, you set up a container query in two parts: define the container, then write child styles that apply when that parent matches the query.

The container-type property is how you define a container.

Use container-type: inline-size to query the container's inline axis, or container-type: size for both the inline and block axes.

Why components use them

Container queries use the @container at-rule.

It resembles @media, except @container reads styling information from a parent container rather than the viewport and user agent.

A card component can adapt its styles according to the container it's placed in.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Container queries; Chrome Developers, Container queries case studies. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: web.dev, Container queries; Chrome Developers, Container queries case studies. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://developers.google.com/site-policies). Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License. Copyright Google LLC.

Cite this

Permanent ID: iil:note:ny6yzpg0

iinventedlight. 2026. "CSS container queries: style a child from its parent's size." iinventedlight Library, iil:note:ny6yzpg0, version of 2026-11-23. https://iinventedlight.com/library/notes/css-container-queries/. License: CC-BY-4.0.

@misc{iil_note_ny6yzpg0,
  author = {{iinventedlight}},
  title = {{CSS container queries: style a child from its parent's size}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/css-container-queries/},
  note = {Permanent ID iil:note:ny6yzpg0. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/css-container-queries.md.