What is Container Query Snippet Generator?
Container queries let you apply CSS styles based on the size of a parent container rather than the viewport. This is different from media queries, which respond to the browser window. For reusable components, container queries mean the same component can render correctly in a narrow sidebar and a wide main content area without duplicating styles.
Quick answer
Use container queries to style an element based on the size of its parent container instead of the viewport. They are the component-level equivalent of media queries and are useful for reusable widget layouts.
Limitations
- Container queries require Chrome 105+, Edge 105+, Firefox 110+, and Safari 16+. Older browsers ignore the feature entirely.
- The container-name property must reference a container-type ancestor in the DOM. Elements outside the container tree cannot query it.
- Container query units (cqw, cqh, cqi, cqb, cqmin, cqmax) are only meaningful inside a @container block and may produce unexpected values outside one.
How to use this tool
- Set a container-type and optional container-name for the parent element that will be the query reference.
- Choose a breakpoint condition such as min-width, max-width, or an inline-size range.
- Write the CSS rules that should apply when the condition is met.
- Copy the generated @container block and place it inside your component stylesheet.
What you can use it for
- Make a card component switch from horizontal to vertical layout when its container shrinks.
- Build a form row that stacks fields on narrow containers and places them inline on wide containers.
- Create a widget that resizes its font and spacing based on the container width, independent of the viewport.