Skip to content
IndexRequest a UIAboutContact

Masonry Columns Layout

Cards of uneven height packed into 2, 3 or 4 columns with CSS columns, showing the top-to-bottom reading order.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean web gallery layout in a masonry style: three columns of rounded cards of different heights packed tightly with even 8px gaps and no empty holes, each card a soft pastel colour block with a small number in the corner, numbers running down the first column and then continuing at the top of the second, light grey page background, flat modern UI, crisp edges. Variants: two wide columns and four narrow columns. Negative: overlapping cards, uneven gaps, shadows, photos, text errors. Reduced motion: static image.

About this pattern

Definition

A masonry layout packs cards of different heights into columns with no row gaps, like bricks. With plain CSS you can get it using column-count: items flow down the first column, then the next, which is cheap and robust but changes the reading order.

Purpose & UX principles

  • column-count sets how many columns; column-gap and a bottom margin set the spacing.
  • break-inside: avoid stops a card from splitting across two columns.
  • Order runs down each column, not across; number the cards to see it.
  • Use it for images and notes of unequal height, not for ranked lists.

Interaction states

  • Three column presets and a Gap slider with numbered cards.

Motion specification

  • The layout reflows instantly.
  • Reduced motion: nothing animates.

Responsive behaviour

  • Change the column count at breakpoints: one on phones, two on tablets, three or more on desktop.
  • Use column-width instead of a count to let the browser choose.

Code

HTML
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Columns"><button data-p="0" aria-pressed="true">3 columns</button><button data-p="1" aria-pressed="false">2 columns</button><button data-p="2" aria-pressed="false">4 columns</button></div><div class="ms" id="ms"></div><label class="rw">Gap <b id="gv">8px</b><input id="gp" type="range" min="2" max="20" value="8"></label><p class="out" id="out"></p></div>

Related patterns

Bento Grid

↗
Bento GridLayout Structures

Modular Grid, Gutters & Margins

↗
Modular Grid, Gutters & MarginsLayout Structures

Container Query Cards

↗
Container Query CardsLayout & Scrolling