CSS Masonry Is Finally Real: grid-lanes (Your Old Syntax Is Stale)
October 9, 2026 | 9 min read | CSS
By Syed · Frontend Engineer & Creator of UITweak
For a decade, a CSS masonry layout meant one of three bad options: a JavaScript library like Masonry.js, a multi-column hack that broke your DOM order, or a snippet from an old blog post using grid-template-rows: masonry that silently did nothing in your browser. Here is the part most tutorials have not caught up with yet: that old snippet is dead. The CSS Working Group finalized a different syntax, display: grid-lanes, and it is already shipping. If you want a native, tab-order-safe Pinterest-style layout in 2026, this is the syntax to learn, and everything you copied before it needs deleting.
30-second version: grid-template-rows: masonry was experimental syntax that never shipped anywhere stable. The final syntax is display: grid-lanes: you define one axis of tracks (columns for waterfall, rows for brick), the browser packs items into lanes, and flow-tolerance keeps tab order sane. Safari 26.4+ ships it; Chrome and Firefox are still behind flags. Wrap it in @supports (display: grid-lanes) and ship today.
The Snippet You Bookmarked Is Dead
Search "css masonry layout" and you will still find hundreds of answers from 2021 to 2024 that look like this:
/* DO NOT USE: dead experimental syntax, works nowhere stable */
.container {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: masonry; /* ignored by every shipping browser */
}That was Firefox's behind-a-flag experiment from the layout.css.grid-template-masonry-value.enabled era, and it was never standardized in that form. The spec moved on, the property shape changed, and the Firefox flag is being updated to the new syntax. Any tutorial, Stack Overflow answer, or AI-generated snippet still serving grid-template-rows: masonry is teaching you syntax that cannot run. The Stack Overflow question "CSS-only masonry layout" is still the top css-grid question of all time at 228 votes, and most of its old answers point at exactly this dead end.
The replacement lives in CSS Grid Layout Level 3 and works as a display value, not a track keyword. That one difference is what makes graceful degradation so easy, as you will see below.
CSS Masonry Layout: The display: grid-lanes Syntax
A waterfall masonry layout in the final syntax is three declarations. You switch the container's display mode to grid-lanes, define the column tracks exactly like normal grid, and the browser packs each item into whichever lane keeps it closest to the top:
.gallery {
display: grid-lanes;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 1rem;
}That is the whole trick. Track sizing is ordinary grid knowledge: fr units, repeat(auto-fill, minmax()) for responsive column counts, unequal fr ratios for editorial rhythms. Item placement uses the grid properties you already know too. grid-column: span 2 widens a card across two lanes, and you can explicitly place items into specific columns. What you do not control is the row: grid lanes decides the vertical packing, which is the point. If you are rusty on the fundamentals, our grid fundamentals guide covers track sizing before you add lanes on top.
Two extra details from the WebKit announcement are worth memorizing. First, the feature deliberately avoids inventing new placement vocabulary: everything you know from grid carries over, and a regular grid can sit inside a grid-lanes container (or the reverse) without conflict. Second, the browser figures out orientation from which axis you defined: columns declared means a waterfall, rows declared means a brick wall, thanks to a new grid-auto-flow: normal default.
Waterfall or Brick: Pick One Axis
Define columns and items flow downward into vertical lanes, the classic Pinterest waterfall. Define rows instead and items pack horizontally into brick rows, like Google Images:
/* waterfall: lanes run vertically */
.waterfall {
display: grid-lanes;
grid-template-columns: repeat(4, 1fr);
gap: 1rem;
}
/* brick: lanes run horizontally */
.brick {
display: grid-lanes;
grid-template-rows: repeat(3, 1fr);
gap: 1rem;
}Define only one axis. That is the whole API for direction for now: the working group is still discussing an explicit orientation property, but since normal is the initial value either way, the one-axis rule works regardless of how that debate lands. One gotcha if a layout misbehaves: check that nothing earlier in your cascade set grid-auto-flow to a conflicting value on the same element. unset it and the automatic orientation returns.
flow-tolerance: Fixing Masonry's Tab-Order Problem
Here is the part every demo glosses over and the part that will actually bite your users. Pure shortest-lane packing has a real accessibility cost: the browser places items by available space, but tab order and screen-reader reading order always follow the DOM. Imagine item 2 ends up three pixels shorter than item 1. The gap under item 2 sits a hair closer to the top, so the next item packs under item 2 and a later item lands under item 1. Visually the page reads left to right on one row and right to left on the next, while the keyboard walks straight through source order. A sighted keyboard user presses Tab and watches focus leap somewhere that makes no spatial sense. That is a failure of WCAG 2.2 success criterion 1.3.2 (meaningful sequence), and it is exactly the problem the old JavaScript libraries had too.
flow-tolerance is the dial the spec added to manage this tension. For each new item the browser asks: is the taller lane shorter than the shortest lane plus the tolerance? If the gap is within tolerance, the item is placed to preserve reading order instead of chasing the absolute shortest column. Only gaps bigger than the tolerance trigger a jump to the genuinely shorter lane. The default is 1em, which treats near-ties as ties. Raise it when your cards vary a lot in height and you want calmer, more predictable placement:
.gallery {
display: grid-lanes;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 1rem;
/* trade a little packing tightness for sane tab order */
flow-tolerance: 3rem;
}The practical rules: keep your DOM order as a sensible reading sequence first, because that is the order keyboards and screen readers use no matter what the layout does. Then set flow-tolerance deliberately. Chasing the last 3% of packing density with a tiny tolerance widens the gap between what people see and what they can operate. Apple's own guidance is to try different values and watch how placement settles. Web Inspector in Safari 26.4 visualizes grid lanes with order numbers projected over each item, so you can literally see where each card landed and why.
Browser Support: Who Actually Runs grid-lanes
This is moving fast, so treat versions as a snapshot verified in early October 2026:
- Safari 26.4+ (macOS and iOS, shipped March 2026): stable and on by default. WebKit did most of the spec work and shipped first. Safari Technology Preview had it since build 234 (December 2025).
- Chrome / Edge 140+: implemented but behind a flag since July 2025. Still behind the flag as of Chromium 151, so not in stable yet.
- Firefox Nightly: behind a flag, and the implementation is being updated from the old
grid-template-rows: masonryexperiment to the finaldisplay: grid-lanessyntax. - Not Baseline yet. MDN still flags grid lanes as limited availability, so do not ship it as your only layout.
The honest read: this is a Safari-first feature through 2026, with Chrome and Firefox converging on the same syntax behind flags. That is precisely the situation @supports was designed for, and it is why the next section exists. As always with fast-moving features, check caniuse before you ship a production build.
Ship CSS Masonry Layout Today: The @supports Recipe
Because grid lanes is a display value, progressive enhancement is nearly free. Browsers that do not understand display: grid-lanes ignore that declaration and keep whatever you set first. So you set a perfectly good regular grid first, then upgrade:
.gallery {
/* fallback everyone gets: a tidy responsive grid */
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 1rem;
}
@supports (display: grid-lanes) {
.gallery {
display: grid-lanes; /* tight packing where supported */
}
}Unsupported browsers get an equal-height grid with extra vertical whitespace. Safari 26.4+ users get the masonry. Nobody gets a broken page, and the fallback keeps working forever even if the spec evolves.
Alternative fallback: CSS columns for tighter packing
If the equal-height grid fallback feels too plain and your cards are not interactive (no links or buttons inside), you can fall back to multi-column instead, which packs tightly everywhere:
.gallery {
/* masonry-like packing for browsers without grid-lanes */
columns: 4 240px;
column-gap: 1rem;
}
.gallery > * {
break-inside: avoid;
margin-bottom: 1rem;
}
@supports (display: grid-lanes) {
.gallery {
display: grid-lanes;
columns: auto; /* clear the column fallback */
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 1rem;
}
.gallery > * {
margin-bottom: 0;
}
}The columns fallback has one cost to weigh honestly: multi-column flows content down each column before moving right, so visual order diverges from DOM order by design. That is why it is only right for non-interactive cards. For interactive cards, the regular grid fallback above is the safe choice, plus flow-tolerance on the grid-lanes upgrade.
Prototype the tracks before you commit
The lanes themselves are just grid tracks, so the fastest way to experiment is to prototype the repeat(auto-fill, minmax()) math visually before writing the final stylesheet. uitweak's Tailwind grid generator lets you dial in column counts and track sizes and see the track math live; take the track definition you land on and drop it into your grid-template-columns above. Same workflow we recommend for bento-style galleries in our bento grid guide, except here grid lanes handles the ragged vertical packing for you.
Decision Tree + Recap
- Your old snippet uses
grid-template-rows: masonry? Delete it. That syntax never shipped anywhere stable. The final syntax isdisplay: grid-lanes. - Waterfall masonry (Pinterest-style):
display: grid-lanes+grid-template-columns. Brick wall (Google Images-style): same display +grid-template-rows. Pick one axis. - Cards contain links or buttons? Set
flow-tolerancegenerously (try3rem+) and keep DOM order reading-friendly. Tab order always follows the DOM. - Ship it today behind
@supports (display: grid-lanes)with a regular grid fallback. Safari 26.4+ gets masonry now; Chrome and Firefox are converging behind flags. - Never ship it as your only layout until it reaches Baseline. It is limited availability as of October 2026.
Related: if your masonry cards use shadows or glass effects that get clipped by parent containers, our box-shadow cut-off fix guide covers the overflow: hidden trap that eats card styling inside packed layouts.
Frequently Asked Questions
Is grid-template-rows: masonry completely dead?
Effectively yes. It was Firefox's behind-a-flag experiment and was never standardized in that form. Firefox's implementation is being migrated to the final display: grid-lanes syntax, and WebKit shipped the final syntax in Safari 26.4. Treat any snippet still using the old form as stale and replace it.
Does flow-tolerance have a keyword value?
In the shipped implementations it takes a length, with 1em as the default. Some early writeups from the experimental period used different names (including a brief stint as item-tolerance in January 2026), so if a tutorial's tolerance declaration does nothing, check the property name first. Stick to lengths like 1em, 3rem, or 0 for the tightest packing.
Can I animate items when the layout repacks?
Layout repacking is not transitionable the way transforms are, so items will jump to their new lanes on resize. The common workaround is FLIP-style animation: measure each card's position before and after, then animate the delta with transform. Entry and exit animations for cards work the usual way with @starting-style and transition-behavior: allow-discrete.
Should I still use a JS masonry library?
Only if you need strict cross-browser pixel parity today, for example an ad-supported feed where every browser must render identically. For everything else, the @supports recipe in this guide is the better trade: Safari users get native packing with zero script weight, everyone else gets a clean grid, and the library can be dropped entirely once the feature reaches Baseline.
Try it: related UI elements
Revenue
$48.2k
12.4%
Stat Card
Copy code →
Featured tile
Spans two columns for emphasis
Fast
Secure
Bento Grid Card
Copy code →
2024
Launched v1.0
First public release with core features.
2025
Reached 10k users
Community growth milestone.
2026
What's next
Roadmap in progress.
Vertical Timeline
Copy code →
Masonry Columns
Copy code →