Masonry Columns

Pinterest style masonry layout using CSS columns with six gradient blocks.

Tailwind CSS
<div class="columns-2 sm:columns-3 gap-3 w-full">
  <div class="break-inside-avoid mb-3 h-28 rounded-xl bg-gradient-to-br from-indigo-400 to-indigo-600"></div>
  <div class="break-inside-avoid mb-3 h-44 rounded-xl bg-gradient-to-br from-rose-400 to-rose-600"></div>
  <div class="break-inside-avoid mb-3 h-20 rounded-xl bg-gradient-to-br from-amber-400 to-amber-600"></div>
  <div class="break-inside-avoid mb-3 h-36 rounded-xl bg-gradient-to-br from-emerald-400 to-emerald-600"></div>
  <div class="break-inside-avoid mb-3 h-24 rounded-xl bg-gradient-to-br from-sky-400 to-sky-600"></div>
  <div class="break-inside-avoid mb-3 h-40 rounded-xl bg-gradient-to-br from-violet-400 to-violet-600"></div>
</div>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Warm palette

The warm palette suits food blogs and travel galleries with a cozy feel.

Tailwind CSS

Four columns

Four columns pack more items per screen on wide desktop galleries.

Tailwind CSS

Pastel

Pastel blocks with soft corners suit lifestyle brands and gentle aesthetics.

Tailwind CSS

About this masonry columns

Masonry layouts pack uneven blocks into columns so vertical space never goes to waste, the look people associate with Pinterest and photo walls. CSS columns give you this staggered rhythm with a single utility and zero JavaScript, which makes it one of the cheapest layout wins in Tailwind.

The wrapper uses columns-2 on phones and columns-3 on larger screens. Every block carries break-inside-avoid so a card never splits across two columns, plus a bottom margin for gutters. The varying heights, from h-20 up to h-44, are what create the classic masonry stagger.

Reach for this when the order across columns does not matter, like galleries, mood boards, or card walls. Avoid it when reading sequence is critical, because columns fill top to bottom in the first column before touching the second, which scrambles order for screen readers and keyboard tabbing.

Uniform grids waste vertical space the moment cards have different heights: short cards leave dead gaps, tall cards stretch their neighbors. Masonry packs uneven blocks into columns so no pixel goes unused, the Pinterest look that makes photo walls and discovery feeds feel abundant. It turns varied content from a layout problem into the aesthetic itself.

The wrapper uses columns-2 on phones and columns-3 on larger screens, a single utility doing the whole layout with zero JavaScript. Every block carries break-inside-avoid so a card never splits across two columns, plus a bottom margin for gutters. The varying heights are what create the staggered rhythm; uniform children would just look like a grid with extra steps.

Add break-inside-avoid to every card; without it, a tall card can split across columns and the severed halves look like a rendering bug. When filtering masonry with JavaScript, animate with FLIP rather than re-laying-out instantly, or the jump disorients. For infinite scroll, append to the shortest column if you control layout in JS, since CSS columns fill strictly in order and can leave one column stubby. Reserve fixed-height ad slots outside the masonry flow; injecting them mid-column shatters the rhythm.

Images without reserved dimensions cause cumulative layout shift: the masonry renders, photos arrive, and every card below them jumps. It looks broken and tanks your CLS score. Always set width and height attributes or an aspect-ratio utility on masonry images so each block holds its shape before the pixels arrive.

Where to use it

  • ✓ Photo and portfolio walls
  • ✓ Pinterest style card feeds
  • ✓ Mood boards and inspiration grids
  • ✓ Mixed-height testimonial walls

Customization tips

Raise the density with sm:columns-4 on wide screens, or drop to a single column on very small phones if two columns feel cramped. Replace the gradient blocks with real cards or images, just keep break-inside-avoid on every child.

Design notes

When to use

Masonry shines for collections of uneven content where fixed rows would leave ugly gaps, like photo walls, recipe cards, or user-generated posts of different lengths. The staggered rhythm feels organic and packs more into the same vertical space, which is exactly the Pinterest look visitors recognize. It works best when browsing matters more than comparing items side by side.

What to avoid

Avoid masonry when reading order matters, because CSS columns fill top to bottom before moving across, so the visual order no longer matches the source order. That makes it a poor fit for ranked lists, timelines, or anything numbered. Also avoid mixing wildly different card heights in shopping listings, where shoppers expect tidy rows they can scan and compare.

Accessibility

The column fill order means screen readers and keyboard users encounter cards in an order that may surprise them, so keep each card self-contained with its actions inside it. Test the tab order on a real page before shipping.

Frequently asked questions

Why does content fill the first column completely before the second?

That is normal CSS column behavior. Columns fill sequentially, top to bottom, before moving to the next column. If you need row-by-row ordering, use a JavaScript masonry library instead.

What does break-inside-avoid actually do?

It stops a block from splitting across two columns. Without it, a tall card could start at the bottom of one column and continue at the top of the next, which looks broken.

Is a CSS columns masonry accessible?

Mostly, but tab order follows the column fill order, which can feel scrambled to keyboard users. Keep interactive controls simple inside masonry, or offer a plain list view as an alternative.

How do I make the masonry responsive with different column counts?

Set column-count with media queries, typically 1 column on mobile, 2 on small tablets, 3 on desktop, and 4 on wide screens. Use column-gap for the gutters and margin-bottom on items for vertical rhythm. The browser reflows items automatically, no JavaScript breakpoints needed.

Why are my masonry cards splitting across columns?

The item is missing break-inside avoid, which tells the browser never to fragment a card between columns. Add it to the card class itself, not the container. Also check for margins collapsing oddly, margin-bottom on the card is the reliable way to space items in a columns layout.

Should I use CSS columns or the native grid-template-rows masonry?

Use CSS columns today, it works in every modern browser and this element relies on it. The native grid-template-rows masonry value is still experimental with patchy support, so it cannot be your only layout. You can layer it as progressive enhancement inside an @supports block once support firms up.