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:
- The container:
.container { container-name: card; container-type: inline-size; }. Per the spec,inline-sizemakes 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. - 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 calledcard, not to any other container in between. - 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
- Rename
.container. Bootstrap and Tailwind both ship a.containerclass with its own max-widths and padding. In a project using either, the generated rule merges with theirs. Rename it, for example to.card-wrap. - Exactly 400 px matches two queries.
min-widthandmax-widthboth include their boundary value, so at exactly 400 px and 700 px two blocks apply. The later block wins because it comes later in the file. That happens to match what the preview shows, but if you reorder the blocks, the boundary width will flip. To avoid it, end ranges at 399.98px or use the range form(400px <= width < 700px). - Don't let the container shrink-wrap. Inline-size containment means the element's width can no longer come from its content. A query container that is
display: inline-block, a float, or a flex item without a set width can collapse to zero. Give it a width from its parent, such as a block element, a grid cell orflex: 1.
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.
Sources
Checked on .
Frequently Asked Questions
Built by Derek Giordano · Part of Ultimate Design Tools