Guide
CSS Container Query Generator online
Build reusable components that respond to their parent containers. Edit typed query conditions, preview independent instances and inspect actual browser matches before exporting your component.
developer tool
Generate CSS container queries, named containers, responsive breakpoints and container units. Resize live components and copy HTML, CSS and Tailwind code.
Guide
Build reusable components that respond to their parent containers. Edit typed query conditions, preview independent instances and inspect actual browser matches before exporting your component.
Choose one of fourteen component templates or twenty-five editable presets.
Configure the wrapper's name, type, writing mode and dimensions.
Add ordered breakpoint blocks with validated conditions and declarations.
Resize individual containers or compare them with a real iframe viewport.
Inspect active queries and unit measurements, then copy or download your code.
Container queries apply styles to a component according to an eligible ancestor rather than the page viewport. A card can stay compact in a sidebar while the same markup expands in a main content area.
Create a wrapper, a descendant component and ordered @container blocks. The five starting modes cover basic rules, named rules, multiple breakpoints, container-unit calculations and custom-property style queries.
Choose a template or preset, select containment and dimensions, then edit query conditions and declarations. Resize the preview, inspect active rules and copy or download the same validated configuration as code.
The browser selects an ancestor eligible for every feature in a condition. Matching blocks participate in the normal CSS cascade. The preview reads sentinel custom properties set inside those actual blocks instead of guessing matches from JavaScript.
For example: .card-wrapper { container-type: inline-size; } @container (width >= 500px) { .responsive-card { display: grid; grid-template-columns: 1fr 2fr; } }. The child changes layout when its wrapper content box reaches 500px.
Inline-size establishes containment in the inline axis. Size contains both axes and can affect intrinsic dimensions; give the wrapper explicit dimensions or suitable layout constraints. Normal does not establish a size-query container.
Use container-name: card to make an ancestor addressable. A rule such as @container card (width >= 600px) targets an eligible ancestor carrying that name. Names are validated conservative CSS identifiers, with reserved keywords rejected.
The declaration container: card / inline-size combines a name and type. This generator can emit either the shorthand or separate declarations. An unnamed shorthand uses none / inline-size.
A named query can skip a nearer container with another name. Keep a separate parent wrapper: size queries generally cannot style their query container based on that container's own dimensions.
Start with 240, 320, 480, 640, 800 or 1024px and adjust them to the content. These are editable component thresholds, not universal device breakpoints. Reorder blocks deliberately because later equal-specificity declarations win.
Media queries respond to a viewport or device-related condition. Container queries respond to eligible ancestors. The comparison uses a real iframe viewport so changing a div's width is never presented as changing the viewport. Both techniques remain useful together.
The calculator explicitly models a single eligible size container. In real nested layouts, each unit can resolve against a different eligible ancestor. When none exists for an axis, the corresponding small viewport dimension supplies the fallback.
One cqw is one percent of eligible container width, while one cqh uses height. For a size container with an 800 by 400px content box, 10cqw is 80px and 10cqh is 40px. Inline-only containment may not supply both axes.
Cqi follows inline size and cqb follows block size. Horizontal writing maps inline to width; vertical writing maps inline to height. The calculator and condition editor account for horizontal-tb, vertical-rl and vertical-lr.
Cqmin uses the smaller of cqi and cqb; cqmax uses the larger. For an eligible horizontal 800 by 400px size container, 10cqmin is 40px and 10cqmax is 80px. Reverse conversion rejects a zero target basis.
The product template puts an illustration above the content in a narrow wrapper and switches to a two-track grid at its configured breakpoint. Edit the base declarations separately from the larger-container declarations.
Dashboard statistics and feature grids demonstrate one-column bases and multi-column query rules. Compare several independent instances to see why a dashboard's narrow widget can differ from its wide content panel.
Enable the outer dashboard and inner sidebar around the card. Give each its own dimensions, type and name, then target those names in separate rules. Browser-computed unit values reveal which axes have eligible ancestors.
Only safe keyword comparisons such as @container style(--density: compact) are offered. They do not promise support for querying arbitrary computed CSS properties. A real preview probe reports local style-query behavior; usable base styling remains available.
A representable single minimum-width rule uses native @min-[500px]/card: variants, with @container/card on the wrapper. An optional @theme container token expresses that threshold. Advanced conditions and multiple rules include supplemental CSS to preserve meaning and cascade order.
Translate class attributes to className and other HTML attributes to their JSX equivalents. Keep the wrapper and child relationship intact, and load the exported CSS through your application stylesheet. Responsive layout itself needs no React state.
Add generated markup to a component and load its scoped CSS using your project's conventions. Ordinary container-query exports need no client-side initializer; the editor's ResizeObserver and iframe infrastructure are only for live inspection.
Add semantic markup in an appropriate block or theme template and place scoped CSS in an approved theme or custom CSS mechanism. Verify that the editor or theme has not removed the wrapper, renamed classes or overridden the query styles.
Retain a readable base layout and optionally wrap containment and queries in @supports. The optional media fallback approximates size conditions using the viewport and cannot reproduce independent component behavior. Test custom-property queries in your target browser matrix.
Check content-box dimensions rather than border-box widths, declare containment on an ancestor, match container names, and use a type eligible for every queried axis. Watch the cascade, vertical writing modes, intrinsic sizing and container-unit viewport fallbacks.
A visual editor that creates validated wrapper markup, container rules, component styles and reusable exports with a native browser preview.
Conditional CSS rules that adapt descendants to eligible ancestor-container dimensions or supported style features.
Container queries inspect an eligible ancestor. Media queries inspect viewport or device conditions. A card can therefore adapt independently of another card in the same viewport.
Give a wrapper container-type: inline-size, place a child inside it and style that child inside a condition such as @container (width >= 500px).
It establishes size-query eligibility in the inline axis only. That is physical width in horizontal writing and physical height in vertical writing.
It establishes eligibility in both axes. Size containment affects intrinsic sizing, so explicit dimensions or appropriate parent constraints are often necessary.
Set container-name: card or container: card / inline-size, then write @container card followed by the condition.
Yes. Add up to fifteen blocks, each with up to eight leaf conditions and forty declarations. Their displayed order preserves the CSS cascade.
Cqw, cqh, cqi, cqb, cqmin and cqmax represent percentages of relevant eligible container dimensions, with small viewport fallbacks where no eligible ancestor exists.
Cqw uses physical width. Cqi follows inline size, which changes with the container's writing mode.
Cqh uses physical height. Cqb follows logical block size, which is physical width in vertical writing.
They use the smaller and larger values of cqi and cqb respectively. The actual eligible ancestors may differ by axis.
Yes. Product, blog, profile, course, pricing and other templates use real @container rules and editable declarations.
Yes. The nested demonstration places a card inside sidebar and dashboard ancestors with independent names, dimensions and containment types.
A size query generally styles descendants of its selected container. Use a separate wrapper around the component you want to change.
They test supported style features on ancestors. This generator restricts them to validated custom properties and safe keyword values, and probes browser behavior in the preview.
The exported responsive behavior is CSS. JavaScript in this editor is used for customization, measurements and exporting.
Yes. The exporter uses verified native container utilities for a representable single minimum-width query and supplemental CSS for advanced conditions or authored multi-rule ordering.
Yes. Adapt the semantic HTML to JSX and import the scoped CSS while preserving the ancestor wrapper.
Yes, through supported custom HTML and CSS or theme mechanisms. Test the final page for sanitization and theme overrides.
Base component styles remain usable. Optional @supports output isolates enhancements, and an optional viewport fallback approximates size rules.
Yes. Download CSS, standalone HTML and version 1 configuration JSON, or copy individual rules and the available output formats.
Yes. Editing, local previews, copy and downloads require no account or payment.
Build visual CSS Grid layouts with editable tracks, gaps and item placement.
Build native Flexbox layouts with live container and item controls.
Design responsive product, profile, pricing and animated cards with copyable HTML and CSS.
Generate fluid padding, margins, gaps and reusable spacing scales.
Queries style descendants of a separate wrapper. Inline-size contains only the inline axis; vertical writing makes that the physical height. Size contains both axes and can suppress intrinsic sizing, so this example gives explicit dimensions. Normal supports eligible style queries, not size queries.
1 / 15 blocks. The displayed order is the CSS cascade order; later declarations of equal specificity win.
Targets map to .responsive-card, -title, -content and -media. An empty container name selects the nearest eligible ancestor.
Up to eight conditions and four nesting levels. Orientation and aspect ratio need size containment. Incompatible size controls are unavailable for normal containers.
Declarations run in the displayed order. Lengths support px, rem, em, %, and all six cq units. Spacing supports multiple values. Fluid font sizes, padding and gaps accept clamp(12px, 4cqi, 32px). Grid tracks: up to six values such as 1fr 2fr.
Declarations run in the displayed order. Lengths support px, rem, em, %, and all six cq units. Spacing supports multiple values. Fluid font sizes, padding and gaps accept clamp(12px, 4cqi, 32px). Grid tracks: up to six values such as 1fr 2fr.
Templates contain fictional content and bundled illustrations. Contact fields are read-only samples with no submission.
Simplified calculator: one eligible size container, using its content-box dimensions. Real preview measurements below also show units that may select different ancestors or fall back to small viewport dimensions.
The card lives inside the sidebar, inside the dashboard. Named queries choose a matching eligible ancestor; unnamed queries choose the nearest eligible ancestor for all features in the condition. Container units select ancestors independently for the axes they need.
Only validated custom-property keyword queries are generated. Arbitrary computed CSS properties are outside this generator. The preview runs a real style-query support probe; base styles remain available if unsupported.
A media fallback approximates eligible size rules using the viewport. It is not behaviorally equivalent to container queries. Style queries keep their base fallback.
Traditional min/max syntax is used where available. Exclusive ranges and logical groups retain modern range syntax. Advanced Tailwind queries retain supplemental CSS in authored order.
Browser viewport: … × …px. The iframe below has its own real viewport; scroll its stage to inspect large containers.
Content-box measurements from ResizeObserver and computed CSS. Active states come from per-query CSS sentinel properties, including when several queries match at once. Text labels accompany every status.
Waiting for browser measurements…