DevTools Logo

CSS Container Queries Lab

CSS Container Queries Lab

Generate container query CSS and preview component patterns locally

Configuration

Breakpoints (px)

Remember: a container query only works when an ancestor declares container-type.

About

A deterministic client-side CSS container query generator with inline-size or size container types, increasing-breakpoint validation, and a resizable live preview for common component patterns.

Examples

Product card at 320 and 640

Input
generateContainerQueryCss({ containerName: "product", containerType: "inline-size", pattern: "card", breakpoints: [320, 640] })
Output
"container-type: inline-size; ... @container (min-width: 320px) ... @container (min-width: 640px)"

Setup block plus one row-layout rule per breakpoint in ascending order.

Decreasing breakpoints warn

Input
validateContainerQueries({ containerName: "layout", containerType: "size", pattern: "nav", breakpoints: [640, 320] })
Output
{ valid: false, warnings: ["Breakpoints should be in strictly increasing order."] }

Out-of-order widths stay renderable but are flagged so the cascade reads top-down.

About this tool

CSS Container Queries Lab generates container setup plus responsive rules with generateContainerQueryCss({ containerName, containerType, pattern, breakpoints }): the preview class gets container-name and container-type, then each breakpoint emits a @container block for the card, nav, or table pattern.

Validation via validateContainerQueries flags missing names, missing container types, empty breakpoint lists, and negative values as errors, while non-increasing breakpoints produce a strictly-increasing-order warning — a zero-width (0px) breakpoint is explicitly allowed.

Output is deterministic: identical inputs always yield byte-identical CSS with breakpoints in the order given, so re-runs diff cleanly.

How to use this tool

  1. Name the container

    Set containerName (sanitized to alphanumerics, dash, underscore) and containerType inline-size or size.

  2. Pick a pattern

    Choose card (stack to row), nav (collapse to flex), or table (rows to cards) for the base plus breakpoint rules.

  3. Add breakpoints

    List pixel widths in strictly increasing order — 0 is valid for a base-up rule.

  4. Validate and copy

    Run validateContainerQueries to clear errors and warnings, then paste the generated CSS.

Use cases

Building reusable card components

Let each card adapt to its own column width instead of the viewport width.

Collapsing navigation per sidebar

Hide links behind a toggle when the nav container — not the window — gets narrow.

Responsive tables in dashboards

Flip dense rows into stacked data-cards below a container threshold.

Common mistakes

Mistake:Forgetting container-type so queries never fire.

Fix:Keep container-type: inline-size (or size) on the wrapper — without it @container rules never match.

Mistake:Listing breakpoints out of order.

Fix:Sort widths ascending; decreasing sequences still emit CSS but trigger the increasing-order warning.

Frequently asked questions

What does this tool do?

It generates container setup plus @container rules with generateContainerQueryCss, and checks inputs with validateContainerQueries for the card, nav, and table patterns.

Can a breakpoint be 0px?

Yes. Zero is a valid non-negative breakpoint — only negative or non-finite values raise an error.

Is my stylesheet uploaded or stored?

No. Pattern templates and breakpoint math run entirely in your browser.

Why is my result marked invalid?

Empty names, missing container types, empty breakpoint lists, and negative widths are errors; decreasing widths only warn about strictly increasing order.

References & standards