---
source: https://iinventedlight.com/library/notes/css-container-queries.md
title: "CSS container queries: style a child from its parent's size"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (web.dev); CC-BY-4.0 (Chrome Developers); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: css-container-queries"
tags: [css, container-queries, responsive, web]
client: Librarian
sources:
  - id: S1
    title: "Container queries"
    publisher: web.dev
    url: https://web.dev/learn/css/container-queries
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "Container queries case studies"
    publisher: Chrome Developers
    url: https://developer.chrome.com/blog/css-ui-ecommerce-cq
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# 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

- [css-grid-basics](https://iinventedlight.com/library/notes/css-grid-basics/)
- [css-flexbox-basics](https://iinventedlight.com/library/notes/css-flexbox-basics/)
- [css-cascade](https://iinventedlight.com/library/notes/css-cascade/)

## Claims

- id: C1
  claim: Container queries style an element from an ancestor's size or state.
  source: S1
  evidence: "adjustments to elements based on the size and state of their ancestors"

- id: C2
  claim: A container query is set up in two parts.
  source: S1
  evidence: "container queries are established in two parts"

- id: C3
  claim: container-type: inline-size queries the container's inline axis.
  source: S1
  evidence: "query the container's inline axis"

- id: C4
  claim: The @container at-rule is how container queries are written.
  source: S2
  evidence: "Container queries use the @container at-rule"

- id: C5
  claim: @container queries a parent container, not the viewport.
  source: S2
  evidence: "queries a parent container for styling information rather than the viewport"

## Sources

- [S1] Container queries. web.dev. https://web.dev/learn/css/container-queries . License: CC-BY-4.0. Accessed 2026-11-23.

- [S2] Container queries case studies. Chrome Developers. https://developer.chrome.com/blog/css-ui-ecommerce-cq . License: CC-BY-4.0. Accessed 2026-11-23.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
