CSS Container Query Generator
Build CSS container queries visually. Define a containment context with container-type and container-name, add responsive breakpoints with @container rules, and get production-ready CSS. Includes a resizable live preview. Everything runs in your browser.
Drag the right edge of the box below to resize the container and see the card respond.
How Container Queries Work
CSS container queries allow you to apply styles to an element based on the size of its nearest containment context, rather than the viewport. This is a game-changer for component-based design because each component can respond to the space available to it.
Step 1: Define a Container
Set container-type on a parent element. Use inline-size for width-based queries (the most common case) or size for both width and height queries. Optionally give it a container-name so you can target it specifically in your @container rules.
Step 2: Write @container Rules
Use @container with size conditions like min-width and max-width to apply different styles depending on the container dimensions. If you specified a container name, use @container card-container (min-width: 400px) to target only that container.
Key Differences from Media Queries
- Scope: Media queries check the viewport; container queries check the parent element
- Reusability: A component using container queries works in any layout context
- Nesting: Container queries work with nested containment contexts
- Browser support: Chrome 105+, Firefox 110+, Safari 16+, Edge 105+