CSS Container Queries Lab
Generate container query CSS and preview component patterns locally
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
generateContainerQueryCss({ containerName: "product", containerType: "inline-size", pattern: "card", breakpoints: [320, 640] })"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
validateContainerQueries({ containerName: "layout", containerType: "size", pattern: "nav", breakpoints: [640, 320] }){ 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
Name the container
Set containerName (sanitized to alphanumerics, dash, underscore) and containerType inline-size or size.
Pick a pattern
Choose card (stack to row), nav (collapse to flex), or table (rows to cards) for the base plus breakpoint rules.
Add breakpoints
List pixel widths in strictly increasing order — 0 is valid for a base-up rule.
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.
Related guides
References & standards
Related tools
APCA Contrast Calculator
Calculate directional APCA 0.1.9 Lc contrast scores and compare them with WCAG 2.1 ratios.
Barcode Generator
Generate barcodes in 8 formats (CODE128, EAN13, UPC, and more) — configure line width, height, and text display, then download as SVG or PNG.
Base64 Image Encoder
Open the Image workspace in Base64 Toolbox to resize and convert images to Base64 data URIs, then copy HTML, CSS, Markdown or JavaScript snippets.
EXIF Viewer & Cleaner
View and remove EXIF metadata from images. See camera info, GPS location, and dates — then download a clean copy.
Favicon Pack Generator
Generate complete favicon packs with all standard sizes and Apple touch icons
Image Compressor
Compress JPEG, PNG, and WebP images in your browser. No uploads, completely private.