Tailwind CSS v4 container queries: @container guide and sizes
Use built-in @container queries in Tailwind CSS v4 with zero plugins: breakpoints table, named containers (@container/card), and @max-* variants.
- Tailwind CSS 4.3.5
In Tailwind CSS v4, container queries are built into core — you no longer need the @tailwindcss/container-queries plugin. Mark any parent with @container and style its children based on the parent's width (@sm:, @md:, @lg:) instead of the browser viewport.
Basic card that adapts to its container
<div className="@container"> <article className="flex flex-col gap-4 @md:flex-row @md:items-center"> <img src="/thumb.webp" alt="" className="aspect-video w-full rounded-lg @md:w-48" /> <div className="flex flex-col gap-1"> <h3 className="font-semibold">UI Pro</h3> <p className="text-sm text-muted-foreground">Adapts in sidebars, grids and modals.</p> </div> </article></div>Drop that same component into a narrow 300px sidebar and it stacks vertically; drop it into a 700px main column on the same desktop screen and it switches to a horizontal row automatically.
Default container breakpoints in Tailwind v4
| Variant | Min width | Pixels |
|---|---|---|
@xs: | 20rem | 320px |
@sm: | 24rem | 384px |
@md: | 28rem | 448px |
@lg: | 32rem | 512px |
@xl: | 36rem | 576px |
@2xl: | 42rem | 672px |
Named containers and max-width queries
- Named containers: Use
@container/cardon the parent and@md/card:grid-cols-2on nested children when you have containers inside containers. - Max-width container queries: Use
@max-md:hiddento hide elements when the container is narrower than28rem. - Arbitrary widths: Use
@[480px]:flex-rowwhen the default steps don't match your card geometry.
Questions
Why is my @md: class not firing even with @container on the same element?
A container cannot query itself. Put @container on the parent wrapper and @md:... on a child inside it.
Do container queries replace sm:/md:/lg: viewport breakpoints?
No — use viewport breakpoints for page-level grids and navigation, and @container for reusable cards, pricing tiles and dashboard widgets that appear in different column widths. See Tailwind CSS v4 vs v3 for the other built-in v4 features.
Related articles
- Tailwind CSS v4Tailwind CSS v4 vs v3: what changed and how to upgradeCompare Tailwind CSS v4 and v3: @theme in CSS, OKLCH colours, renamed utilities, breaking defaults, and the exact upgrade steps with @tailwindcss/upgrade.
- Tailwind CSS v4Tailwind v4 arbitrary values not working: five causes and fixesFix broken arbitrary values in Tailwind CSS v4: parentheses for CSS variables bg-(--x), underscores for spaces, dynamic strings, type hints and @source.
- Tailwind CSS v4Does Tailwind CSS v4 have a config file?Not by default: v4 is configured in CSS with @theme. Where every v3 setting went, how to load an old tailwind.config.js with @config, and when to keep it.
Still stuck? We answer every message ourselves. Write to us