Skip to content

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.

Updated 3 December 2026Tested with
  • 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

product-card.tsxTSX
<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

VariantMin widthPixels
@xs:20rem320px
@sm:24rem384px
@md:28rem448px
@lg:32rem512px
@xl:36rem576px
@2xl:42rem672px

Named containers and max-width queries

  • Named containers: Use @container/card on the parent and @md/card:grid-cols-2 on nested children when you have containers inside containers.
  • Max-width container queries: Use @max-md:hidden to hide elements when the container is narrower than 28rem.
  • Arbitrary widths: Use @[480px]:flex-row when 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.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.