Masonry Layouts With Grid Lanes
The new display: grid-lanes for masonry layouts, where items of different heights pack into the shortest column: defining lanes, spanning and placing items, fit-tolerance, reading order, browser support, and falling back to a regular grid.
kvi5hnuCode Sprout team member7 min readOn this page
A masonry layout, like a photo wall or a pin board, puts items of different heights into columns and stacks each one directly under the item above, with no gaps. A regular grid can't do it: its rows are as tall as their tallest item, so shorter items leave holes underneath. For years, masonry meant JavaScript libraries or CSS multi-column tricks that put items in the wrong order.
CSS now has a native solution, grid lanes: display: grid-lanes. It's new, and only in Safari so far, but it falls back cleanly to a regular grid.
How grid lanes work

A grid-lanes container has tracks on one axis only, called lanes. Items are taken in source order, and each one is placed into the lane where it would end up closest to the start, like a car changing into the lane that lets it get furthest ahead. There are no rows: items in neighbouring lanes don't line up with each other.
.wall {
display: grid-lanes;
grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); /* the lanes */
gap: 1rem;
}
Everything about the lane definition is regular grid (articles 66 and 67): repeat(), auto-fill, minmax(), fr and named lines all work, and gap spaces both the lanes and the items within a lane.
- Lanes defined with
grid-template-columnsgive a vertical, "waterfall" masonry: columns that items stack down. - Lanes defined with
grid-template-rowsgive a horizontal, "brick" layout: rows that items line up along.
display: inline-grid-lanes makes an inline-level container.
Spanning and placing items
Items can span several lanes, and can be placed in specific lanes, with the usual properties:
.wall .feature { grid-column: span 2; } /* two lanes wide, placed wherever it fits best */
.wall .pinned { grid-column: -3 / -1; } /* always in the last two lanes */
Placed items are positioned first, like in grid (article 69), and the rest pack around them.
fit-tolerance
If one lane is only 2px shorter than another, choosing it makes items jump between lanes for no visible benefit. fit-tolerance sets how much shorter a lane must be to count as shorter: differences below it are treated as ties, and among tied lanes the browser picks the first one after the lane of the previous item, wrapping back to the first lane when there's none, so placement keeps moving forward across the lanes.
.wall { fit-tolerance: 2rem; } /* only change lanes for a real gain */
The default, normal, means 1em in grid lanes. A larger value keeps items closer to reading order; 0 always picks the strictly shortest lane. The property was renamed twice during design: item-tolerance, then flow-tolerance (Safari 26.4), and finally fit-tolerance (Safari 27.2), which keeps flow-tolerance as an alternative name.
Reading order
Items are placed in source order, and each goes near the top of the layout, so the visual order roughly follows the HTML from top to bottom, across the lanes. That's much better than the old multi-column trick, which filled the first column completely before the second, so items 1, 2, 3 ran down the left side. Keyboard focus follows the HTML order, which in grid lanes mostly moves across the lanes and down.
It's not exact: a tall item can make later items appear above it in a neighbouring lane. Keep fit-tolerance reasonable, and for content that must be read in order, like a list of articles, consider a regular grid instead. The reading-flow property (article 64) is meant for layouts like this, where the visual order and the source order can drift apart.
Support and fallbacks
| Browser | display: grid-lanes |
|---|---|
| Safari | 26.4 |
| Chrome, Edge | behind a flag (chrome://flags, "CSS Grid Lanes layout"), not shipped |
| Firefox | in preview builds, not shipped |
The name went through several drafts: grid-template-rows: masonry (Firefox's early experiment), then a proposed display: masonry, before the CSS Working Group chose display: grid-lanes. Older articles use those names, which don't work.
Grid lanes are an ideal progressive enhancement. A browser that doesn't recognise grid-lanes drops the declaration and uses the previous one, and the lane definition is valid grid:
.wall {
display: grid; /* everyone */
display: grid-lanes; /* browsers with grid lanes */
grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
gap: 1rem;
}
Tested in Chrome 157, which doesn't support grid lanes: the computed display is grid, and the items form a normal grid with rows. Users get aligned rows with some empty space instead of a tight wall, and nothing breaks. For changes that only make sense with grid lanes, such as different spans, use @supports (display: grid-lanes) { … }.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.status::before { content: "This browser doesn't support grid lanes: you're seeing the grid fallback."; }
@supports (display: grid-lanes) {
.status::before { content: "Grid lanes are supported: items pack into the shortest lane."; }
}
.wall {
display: grid;
display: grid-lanes;
grid-template-columns: repeat(auto-fill, minmax(5rem, 1fr));
gap: 0.4rem;
}
.wall figure {
margin: 0; block-size: var(--h);
display: grid; place-items: center;
background: #f4efe6; border: 1px solid #8a3b12; border-radius: 6px;
}
In a browser without grid lanes, the items sit in rows, with empty space under the shorter ones. In Safari 26.4 and later, they pack into tight columns.
Grid lanes compared with the alternatives
| Approach | Order | Notes |
|---|---|---|
display: grid-lanes | source order, across lanes | the native solution; Safari only so far |
| regular grid | source order, in rows | aligned rows, with gaps under short items |
| multi-column layout (article 73) | down each column, then across | tight packing, but the order is wrong for most galleries |
| JavaScript libraries | across, by shortest column | works everywhere; costs script and layout work |

These are the two fallbacks that work today: a regular grid keeps reading order across the rows at the cost of gaps, and multi-column packs tightly but reorders the items down the columns. Grid lanes give the tight packing while keeping items 1, 2 and 3 across the top.
What's current
display: grid-lanesandinline-grid-lanes: Safari 26.4;fit-tolerance: Safari 27.2.- Chrome and Firefox are implementing it, behind flags and in previews.
- The direction control is still being discussed: for now, the axis comes from which template property defines the lanes.
Common questions
Can I use grid lanes today?
Yes, as an enhancement: write display: grid first, then display: grid-lanes. Safari users get masonry, others get a regular grid.
What happened to grid-template-rows: masonry?
It was an earlier proposal, only in Firefox behind a flag. The final syntax is display: grid-lanes.
Why don't items line up horizontally? That's the point of lanes: there are no rows. If items should line up, use a regular grid.
What does fit-tolerance do?
It sets how much shorter a lane must be before an item skips ahead of a tied lane into it. The default, normal, means 1em.
Summary
display: grid-lanescreates a masonry layout: lanes on one axis, items packed into the lane that ends highest.- Define lanes with
grid-template-columns(vertical masonry) orgrid-template-rows(horizontal). - Spans, placement,
repeat(),minmax()andgapwork as in grid. fit-tolerance(default1em) reduces lane jumping.- It's in Safari 26.4+; elsewhere,
display: gridbefore it gives a clean fallback.
Practice questions
Write CSS for a photo wall with lanes at least 12rem wide, using grid lanes where supported and a regular grid otherwise.
Answer
.photos {
display: grid;
display: grid-lanes;
grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr));
gap: 0.5rem;
}
Three lanes end at 300px, 290px and 320px, and the previous item went into the third lane. With the default fit-tolerance of 1em (16px), which lane does the next item go into?
Answer
The first lane. The second is only 10px shorter, below the tolerance, so lanes 1 and 2 are tied. There's no tied lane after the third, so placement wraps around to the first tied lane, lane 1.
Why is multi-column layout a poor substitute for masonry in a gallery of newest-first photos?
Answer
Multi-column fills the first column completely before the second, so the newest photos all run down the left side, and the top row isn't the newest items. Grid lanes place items across the lanes in source order.
How do you make a horizontal brick layout with three rows of lanes?
Answer
.bricks { display: grid-lanes; grid-template-rows: repeat(3, auto); gap: 0.5rem; }
Lanes defined by rows make items flow along the rows.
Previous: Subgrid: Aligning Nested Content to the Parent Grid
Next: Multi-Column Layout: columns, column-span and Fragmentation

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.