ReferenceShape and layout tokens
Default to grid. Use gap, not margin. Set constraints, not fixed dimensions. Let the browser do the work.
The 1D versus 2D framing is a false distinction. The real question is who controls sizing.
The container defines tracks and places content inside them. Columns are consistent regardless of content variation. It's the default for most layouts, including vertical stacks.
grid gap-4grid grid-cols-3 gap-4grid place-content-centerItems negotiate their own sizes based on content. It's ideal when layout should follow content, such as tags, nav items, pill lists, and wrapping rows where items should be as wide as they need to be.
flex items-center gap-4flex flex-wrap gap-2Based on a 4px unit. Use it with gap-, p-, m-, w-, and h-. On the
docs site, each common step is a bar as wide as the step, with its size in
pixels.
00.511.52345681012162024Viewport breakpoints are for page-level layout. Prefix a class with one, such
as sm:grid-cols-2, to apply it from that width up. On the docs site, each
breakpoint is listed with its width.
sm:40rem (640px)md:48rem (768px)lg:64rem (1024px)xl:80rem (1280px)2xl:96rem (1536px)The container-* utility centres content with responsive horizontal padding
and a configurable max width. It replaces the v1 <Container> component.
<div className='container-8xl'>...</div><div className='container-4xl'>...</div>
Any --container-* token works: Tailwind's 3xs to 7xl plus Roadie's
8xl. On the docs site, each width is listed with its class.
container-3xs16rem (256px)container-2xs18rem (288px)container-xs20rem (320px)container-sm24rem (384px)container-md28rem (448px)container-lg32rem (512px)container-xl36rem (576px)container-2xl42rem (672px)container-3xl48rem (768px)container-4xl56rem (896px)container-5xl64rem (1024px)container-6xl72rem (1152px)container-7xl80rem (1280px)container-8xl90rem (1440px)| Breakpoint | Inline padding |
|---|---|
| Default | 1.5rem (24px) |
md | 2rem (32px) |
lg | 3rem (48px) |
Set constraints, not fixed dimensions. Let content breathe and the layout flex.
Use min-h- and max-w- instead of h- and w-. Fixed dimensions clip
content. Constraints let it grow.
Block elements default to width: auto, which accounts for margins and
padding. Don't set w-full or w-screen unless you have a concrete reason.
w-fit sizes an element to its content. It's useful for buttons, badges, and
inline elements that shouldn't stretch in a grid.
Use fr units in grid templates to distribute available space. Use
minmax(0, 1fr) to stop content from forcing columns wider than intended.
Components should respond to their parent, not the viewport. A card in a
narrow sidebar needs different styling than the same card in a wide main
column, though the viewport width is the same in both cases. Use @container
for component-level adaptation.
Tailwind's @container class sets container-type: inline-size. Then use
@sm:, @md:, @lg:, and so on as container query variants instead of
sm: and md:. They switch at the container widths, so @sm: applies once
the container is container-sm wide.
Both cards use the same @sm:grid-cols-[auto_1fr] breakpoint. The narrow one,
capped at max-w-xs, stacks because its container is too small. The wider one
goes side by side once it has room.
Use media queries for page-level layout and container queries for component-level adaptation. Use both.
grid gap-4 is the default vertical layout.
grid place-content-center centres both axes with one class.
flex items-center gap-4 gives content-driven sizing.
grid grid-cols-3 gap-4 lets the parent control column widths.
grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 adds columns as the
viewport grows.
grid grid-cols-[1fr_2fr] gap-6 gives the second column twice the space.
flex flex-wrap gap-2 lets items wrap naturally based on content width. This
is where flexbox shines: children control their own size.
gap-4, not mb-4 on children. Gap never creates edge spacing.grid gap-4, not flex flex-col gap-4. Grid is simpler for vertical
stacks.grid place-content-center, not flex items-center justify-center.
One class centres both axes.grid grid-cols-3, not flex with calc(33%). Grid handles equal
columns natively.min-h-[200px], not h-[200px]. Content can grow beyond a fixed
height.max-w-4xl, not w-full. It caps the width and stays responsive.minmax(0, 1fr), not fixed 300px columns. Fixed units cause overflow
on small screens.Respond to the parent with @container and the @sm: variants, not to the viewport with sm: and md:.
Do
Respond to parent width so the component adapts regardless of where it is placed.
{/* Responds to viewport, breaks in narrow columns */}<div className="grid md:grid-cols-[auto_1fr]"><img /><div>Content</div></div>
Don’t
Respond to the viewport. It breaks when the same component is placed in a narrow column.