Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Grid

Masonry layout

Concept page on CSS masonry layout: what it is, its experimental status and changing syntax, and how to build a similar result today with multi-column.

A masonry layout packs items of different heights into columns without leaving the gaps a normal grid produces: each new item goes into the shortest column, like bricks in a wall. Photo galleries and card walls are typical examples.

This is an experimental area. CSS has a proposal to do it natively, but the syntax has changed over time (an earlier form used grid-template-rows: masonry, newer work uses a dedicated grid-lanes display value) and browser support is partial or behind flags. Check current browser documentation before relying on any native syntax, and do not ship it without a fallback. This page therefore shows what works everywhere today.

What a plain grid does

In an ordinary grid every item sits in a row track, and the row takes the height of its tallest item. Short items leave empty space beneath them. That is right for aligned cards, but wrong for a wall of pictures.

Fallback: multi-column

The columns properties fill one column top to bottom before starting the next. Items are never cut if you add break-inside: avoid, and every column has natural heights.

Try it

A masonry-like wall with multi-column

Usage notes

  • Reading order differs. Multi-column orders items down each column, so the visual order (1, 4, 7 across the top) differs from the sequence in the HTML. For sorted content such as search results, prefer a normal grid.
  • Balanced columns, not shortest-first. Multi-column balances the total height; it does not place each item into the currently shortest column.
  • JavaScript libraries place absolutely positioned items to get true masonry, at the cost of script and layout work.
  • Grid with fixed spans. If you know item heights, grid-row: span N with grid-auto-rows and grid-auto-flow: dense gets a similar look with no scripting.
  • Use @supports to switch to any native masonry syntax only where it is understood, leaving the fallback for the rest.

Browser support

Limited and experimental at the time of writing; treat all native masonry syntax as unavailable for production unless you test it yourself. The multi-column fallback shown here works in every browser.