Container Query Builder

What Is Container Query Builder?

Container Query Builder generates CSS container queries — the modern alternative to media queries that lets components respond to their parent container’s size rather than the viewport. This makes truly reusable, context-aware components that adapt whether they’re in a sidebar, a main column, or a full-width section.

How to Use This Tool

Define your container element and set breakpoint conditions (min-width or max-width). Add the CSS rules you want applied at each breakpoint, and preview the responsive behavior in real time by resizing the container. Copy the generated CSS when you’re satisfied. Everything runs in your browser.

Why Use Container Query Builder?

Container queries are powerful but their syntax is new and easy to get wrong. This tool provides a visual builder that lets you see the responsive behavior immediately, eliminating guesswork. It generates clean, production-ready CSS you can drop into any project — for free and with no signup. For a detailed walkthrough, see our step-by-step guide.

Common Use Cases

Card components that appear in both a narrow sidebar and a wide hero region, where media queries fail because the viewport is the same in both placements but the container is not. Reusable layout primitives in a design system, sized to whatever slot they end up in. Email-style two-column layouts that need to collapse when the parent shrinks below a threshold, regardless of viewport width.

Dashboard widgets that get rearranged by users into different grid cells — each widget knows its own container size and adapts independently. Marketing site blocks that ship in different page templates with different surrounding constraints. Migrating a mature design system from media-query-based responsive logic to container-based, where the builder helps shape the syntax of the new @container rules.

Worked example: what the default output does, line by line

The builder starts with three layouts for a container named card: below 400 px, 400–700 px and 700 px and up. We read the CSS it generates and checked it against the CSS Containment Level 3 specification on October 12, 2026. The output has three parts:

  1. The container: .container { container-name: card; container-type: inline-size; }. Per the spec, inline-size makes the element a query container for its own inline axis (its width in horizontal writing). It also applies layout, style and inline-size containment to that element.
  2. The queries: @container card (max-width: 400px), then @container card (min-width: 400px) and (max-width: 700px), and so on. Naming the container means the rules only respond to the nearest ancestor called card, not to any other container in between.
  3. The target: every rule styles .card-content, a child of the container. That is required, not a style choice. A container query can't change the container itself, only its descendants, so put the content inside an inner element.

Three things to adjust before pasting

Support is broad. MDN's compatibility data lists @container, container-type and the container units (cqi, cqw and others) in Chrome and Edge 105, Firefox 110 and Safari 16. Style queries on custom properties, @container style(--x: y), came later: Chrome 111, Safari 18 and Firefox 151. In older browsers the @container blocks are ignored and only your base styles apply.

Frequently Asked Questions

What are CSS container queries?+
Container queries let components respond to the size of their parent container rather than the viewport. This makes truly reusable components that adapt whether they're in a sidebar, main content area, or full-width section.
How do container queries differ from media queries?+
Media queries respond to the viewport (browser window) size. Container queries respond to a specific container element's size. This means a card component can have different layouts based on where it's placed, not just the screen size.
What is container-type?+
The container-type property defines what dimensions the container query can respond to. 'inline-size' (most common) enables queries based on width. 'size' enables both width and height queries. 'normal' disables containment.
Do container queries have good browser support?+
Yes. Container queries are supported in all modern browsers including Chrome 105+, Firefox 110+, Safari 16+, and Edge 105+. They are production-ready for most projects.
What browser support do container queries have?+
Size container queries are in Chrome and Edge 105+, Firefox 110+ and Safari 16+ (MDN compatibility data). This builder does not generate a media-query fallback; in older browsers the @container blocks are ignored and your base styles apply, so make the base layout the narrow one.
Do I need to declare container-type on the parent?+
Yes. The parent needs container-type: inline-size (most common) or size to be queryable. The builder outputs it on a .container rule, together with container-name; rename that class if your framework already uses .container.
Can container queries query the container’s aspect ratio?+
Size queries such as @container (aspect-ratio > 16/9) are part of the same spec and work wherever container queries do. This generator builds min-width and max-width conditions only, so add an aspect-ratio condition by hand if you need one.
What is the browser support for container queries?+
The @container rule, container-type and container units (cqi, cqw and others) are supported in Chrome and Edge 105+, Firefox 110+ and Safari 16+. Style queries on custom properties arrived later (Chrome 111, Safari 18, Firefox 151). Browsers without support ignore the @container block and the default styles apply.
Why are my container queries not working?+
The most common reason is forgetting to set container-type on the containing element. A container query targets the nearest ancestor with container-type set to inline-size or size; without that property, the query has no container to measure against and falls back to the viewport. The builder always emits the container-type rule alongside the @container blocks, so copy both. The other common issue is querying a container that is itself sized by its content (intrinsic sizing), which can create circular layout calculations.

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service