Tailwind CSS Handbook v4.3

Container & Columns

Constrain page width with the container utility or the max-w-* pattern, and flow text into newspaper-style columns with the columns-* utilities.

Two related jobs: keeping content from stretching too wide, and splitting content into columns.

The container utility#

container sets max-width to the current breakpoint, so the element steps up in width as the viewport grows.

Breakpointcontainer max-width
Below sm100%
sm40rem
md48rem
lg64rem
xl80rem
2xl96rem
HTML
<div class="container mx-auto px-6">…</div>

Customising container#

Because container is now an ordinary utility, you override it with @utility:

CSS
@import "tailwindcss";

@utility container {
  margin-inline: auto;
  padding-inline: --spacing(6);
}

Now class="container" alone is centred and padded.

The max-w-* pattern Recommended#

Most modern layouts skip container entirely and use an explicit max width:

HTML
<div class="mx-auto max-w-7xl px-6 lg:px-8">…</div>

Why this is usually better:

  • The width is stated, not derived from breakpoints.
  • It does not jump at breakpoints — it grows smoothly to a ceiling.
  • Different sections can use different ceilings (max-w-3xl for prose, max-w-7xl for a grid).
UtilityWidthGood for
max-w-prose~65 charactersBody copy
max-w-3xl48remArticles, forms
max-w-5xl64remDocumentation
max-w-7xl80remMarketing pages, dashboards
max-w-screen-lgThe lg breakpointMatching a breakpoint exactly
Loading preview…

max-w-* draws from the --container-* theme namespace, which is the same namespace that powers container query variants.

Multi-column text#

columns-* flows content into newspaper-style columns. The browser balances the content automatically.

UtilityCSS
columns-2 … columns-12Fixed column count
columns-3xs … columns-7xlIdeal column width; count adapts
columns-autoBrowser decides
gap-8Gutter between columns
Loading preview…

Controlling breaks#

UtilityPurpose
break-inside-avoidKeep an element from splitting across columns
break-before-column / break-after-columnForce a column break
break-before-page / break-after-pagePage breaks when printing
HTML
<div class="columns-2 gap-8">
  <figure class="mb-4 break-inside-avoid">
    <img src="…" alt="">
    <figcaption>Stays whole.</figcaption>
  </figure>
</div>

Masonry-style galleries#

HTML
<div class="columns-2 gap-4 md:columns-3">
  <img class="mb-4 w-full break-inside-avoid rounded-lg" src="…" alt="">
  <img class="mb-4 w-full break-inside-avoid rounded-lg" src="…" alt="">
</div>

Choosing an approach#

NeedUse
Page width constraintmx-auto max-w-7xl px-6
Breakpoint-stepped widthcontainer mx-auto px-6
Readable article widthmax-w-prose or max-w-3xl
Newspaper text flowcolumns-*
Card gallery with equal rowsGrid
Card gallery with ragged heightscolumns-* + break-inside-avoid

Common mistakes#

  • Expecting container to centre itself. Add mx-auto in v4.
  • No horizontal padding. max-w-7xl alone lets text touch the screen edge on phones. Always pair with px-*.
  • Nesting containers. One width constraint per section is enough.
  • Using columns-* for layout. It is for content flow. Anything interactive or order-sensitive belongs in a grid.
  • Forgetting break-inside-avoid. Cards and figures split across columns without it.