Skip to main content

developer tool

CSS Container Query Generator

Generate CSS container queries, named containers, responsive breakpoints and container units. Resize live components and copy HTML, CSS and Tailwind code.

Loading tool…

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.

How to use CSS Container Query Generator

1

Choose a component

Choose one of fourteen component templates or twenty-five editable presets.

2

Set up containment

Configure the wrapper's name, type, writing mode and dimensions.

3

Build query rules

Add ordered breakpoint blocks with validated conditions and declarations.

4

Resize and compare

Resize individual containers or compare them with a real iframe viewport.

5

Export the component

Inspect active queries and unit measurements, then copy or download your code.

What are CSS container queries?

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.

What the generator builds

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.

How to use this generator

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.

How query evaluation works

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.

Writing an @container rule

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.

Choosing container-type

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.

Naming query containers

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 container shorthand

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.

Named ancestors and descendant styling

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.

Component breakpoint systems

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.

Container queries versus media queries

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.

Container-relative units

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.

Physical units: cqw and cqh

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.

Logical units: cqi and cqb

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.

Minimum and maximum container units

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.

Responsive product cards

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.

Responsive dashboard components

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.

Nested container queries

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.

Custom-property style queries

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.

Tailwind CSS v4 integration

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.

Using container queries in React

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.

Using container queries in Next.js

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.

Using container queries in WordPress

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.

Browser compatibility and progressive enhancement

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.

Common container-query mistakes

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.

Common uses for CSS Container Query Generator

  • Responsive cards reused in sidebars and main content.
  • Dashboard widgets with independent component breakpoints.
  • Teaching logical axes, nested ancestry and viewport comparisons.
  • Exporting scoped CSS and Tailwind v4 integration examples.

Why use this developer tool?

  • Native browser queries and computed-style match indicators.
  • Named and unnamed ancestors, logical groups and safe custom-property style queries.
  • Six container-relative units with forward and reverse calculations.
  • Dependency-free standalone HTML and reusable versioned configuration.

CSS Container Query Generator FAQ

What is a CSS Container Query Generator?

A visual editor that creates validated wrapper markup, container rules, component styles and reusable exports with a native browser preview.

What are CSS container queries?

Conditional CSS rules that adapt descendants to eligible ancestor-container dimensions or supported style features.

What is the difference between container queries and media queries?

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.

How do I use the CSS @container rule?

Give a wrapper container-type: inline-size, place a child inside it and style that child inside a condition such as @container (width >= 500px).

What is container-type inline-size?

It establishes size-query eligibility in the inline axis only. That is physical width in horizontal writing and physical height in vertical writing.

What is container-type size?

It establishes eligibility in both axes. Size containment affects intrinsic sizing, so explicit dimensions or appropriate parent constraints are often necessary.

How do I create a named container?

Set container-name: card or container: card / inline-size, then write @container card followed by the condition.

Can I use multiple container-query breakpoints?

Yes. Add up to fifteen blocks, each with up to eight leaf conditions and forty declarations. Their displayed order preserves the CSS cascade.

What are CSS container-relative units?

Cqw, cqh, cqi, cqb, cqmin and cqmax represent percentages of relevant eligible container dimensions, with small viewport fallbacks where no eligible ancestor exists.

What is the difference between cqw and cqi?

Cqw uses physical width. Cqi follows inline size, which changes with the container's writing mode.

What is the difference between cqh and cqb?

Cqh uses physical height. Cqb follows logical block size, which is physical width in vertical writing.

What are cqmin and cqmax?

They use the smaller and larger values of cqi and cqb respectively. The actual eligible ancestors may differ by axis.

Can I use container queries for responsive cards?

Yes. Product, blog, profile, course, pricing and other templates use real @container rules and editable declarations.

Can I use nested container queries?

Yes. The nested demonstration places a card inside sidebar and dashboard ancestors with independent names, dimensions and containment types.

Can a container query style its own container?

A size query generally styles descendants of its selected container. Use a separate wrapper around the component you want to change.

What are CSS style queries?

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.

Do CSS container queries require JavaScript?

The exported responsive behavior is CSS. JavaScript in this editor is used for customization, measurements and exporting.

Can I use container queries in Tailwind CSS v4?

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.

Can I use container queries in React and Next.js?

Yes. Adapt the semantic HTML to JSX and import the scoped CSS while preserving the ancestor wrapper.

Can I use container queries in WordPress?

Yes, through supported custom HTML and CSS or theme mechanisms. Test the final page for sanitization and theme overrides.

What happens if a browser does not support container queries?

Base component styles remain usable. Optional @supports output isolates enhancements, and an optional viewport fallback approximates size rules.

Can I download the generated CSS?

Yes. Download CSS, standalone HTML and version 1 configuration JSON, or copy individual rules and the available output formats.

Is the CSS Container Query Generator free?

Yes. Editing, local previews, copy and downloads require no account or payment.

Related Tools