Container query: plainly explained.

A container query applies CSS based on a parent's size, not the screen. How it works, container versus media query, and container query units.

Design · Updated Nov 7, 2026

DEFINITION

A container query applies CSS based on the size of a parent container, not the whole screen, so a component adapts to wherever it is placed.

CATEGORY

Design

RELATED

Responsive design, Media query

Summarize this page with AI

A container query applies styles based on the size of a parent container rather than the size of the whole viewport. It lets a component adapt to the space it actually sits in, so the same card looks right in a wide main column and in a narrow sidebar. It is the piece responsive design was missing for true component-based layouts.

01

How a container query works

You mark an element as a query container, then write rules against its width.

  • Declare the container: .card-wrap { container-type: inline-size; }
  • Query it: @container (min-width: 400px) { .card { display: flex; } }
  • Optionally name it with container-name to target a specific ancestor.
02

Container query versus media query

Both apply conditional styles, but they measure different things.

Aspect
MeasuresMedia queryThe viewport (whole screen)Container queryA parent container
Best forMedia queryPage-level layoutContainer queryReusable components
ReusabilityMedia queryTied to screen sizeContainer queryWorks anywhere it is placed
03

Container query units

Alongside the rules, container query units size against the container: cqw (1% of container width), cqh (height), and cqi / cqb (inline and block size). They let type and spacing scale with the component instead of the screen.

04

Why it matters for design systems

In a component-based system, the same card, list or media object is dropped into many layouts. Media queries cannot know how wide that slot is; container queries can. This makes components truly self-contained and is why design systems adopted them quickly.

05

Browser support and best practices

Container queries are supported across all modern browsers. Declare the container on a wrapper rather than the component itself so the component stays reusable, and keep viewport media queries for page-level structure while using container queries for the pieces inside.

06

Container queries at BeBranded

At BeBranded we build components that adapt to their slot with container queries, so a card behaves correctly wherever it lands. It is part of the systematic, component-driven front-end in our design work.

FAQ

Questions about Container query.

Another question?

Write to us
What is a container query?
A container query applies CSS based on the size of a parent container instead of the viewport, so a component adapts to the space it sits in rather than the whole screen.
What is the difference between a container query and a media query?
A media query responds to the viewport size, while a container query responds to a parent container. Media queries suit page layout; container queries suit reusable components.
How do you write a container query?
Set container-type: inline-size on a wrapper, then write @container (min-width: 400px) { ... }. The rules apply based on that container's width, not the screen.
What are container query units?
Units like cqw, cqh, cqi and cqb size relative to the container: cqw is 1% of its width. They let type and spacing scale with the component instead of the viewport.
Are container queries supported?
Yes. Container queries are supported across all modern browsers, so they are safe to use on current projects, with a graceful fallback for very old ones.
When should I use a container query instead of a media query?
Use a container query for a reusable component that can appear in different widths, and a media query for the overall page layout. They complement each other.

Related

Related terms, and where to go next.

BeBranded
Development

REM CSS: complete guide to responsive design

REM CSS: definition, differences with px and em, conversion, how to use it in Webflow, accessibility, and best practices for responsive design.

Read the article
GSAP: complete guide to web animation in 2026
Design

GSAP: complete guide to web animation in 2026

GSAP (GreenSock): definition, key plugins, Webflow acquisition, practical integration, CSS animation comparison, and how to get started.

Read the article
BeBranded
Development

Figma to Webflow: plugin or Client-First rebuild in 2026

Figma to Webflow plugin or manual Client-First rebuild? Comparison, recommended workflow, and real-world scenarios to ship fast without sacrificing quality.

Read the article

Let’s talk

Tell us what you want to build.

Thirty minutes with the people who will work on your project. You leave with a clear view of the scope, the timeline and the next steps.

What happens next

  1. 1A 30-minute callWe listen to your goals, your constraints and your context.
  2. 2A clear scopeWe map what is worth doing first, and what it takes.
  3. 3A costed proposalYou decide, with no commitment and no sales pitch.