This note has an interactive demo. Try it in the original
Masonry layouts, the Pinterest-style wall of cards with different heights, finally have a native CSS value: display: grid-lanes. Safari ships it, and Safari 27.2 (WebKit's release post is from October 26) just renamed the one property that controls how it behaves. Chrome and Firefox aren't there yet, so this is a good moment to learn how it works and how to use it today without breaking anything.
What it is and why it matters
For years, a masonry wall meant a JavaScript library measuring every card and positioning it absolutely. CSS Grid alone can't do it: rows force every card in a row to share the same height, so short cards leave holes under them. Multi-column layout packs things tightly, but it fills the first column top to bottom before moving to the next, so items 1, 2 and 3 end up stacked on the left instead of reading across.
Grid Lanes, defined in CSS Grid Layout Level 3, sits in between. One axis is a real grid (your columns), and the other axis is a stacking axis with no rows. MDN sums it up well: "each row of items loads into the column with the most room, causing a tightly packed layout without strict row tracks."
The demo above lets you switch between grid and grid-lanes with the same cards. Watch the board height drop and the gaps disappear.
How it works
This is the whole thing, and it's the same CSS the demo uses:
.board {
display: grid-lanes;
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
gap: 10px;
}
You define columns exactly as you would in a normal grid. The browser then places each card, in order, into "whichever grid track is currently the least filled", in the spec's words. Everything you know from Grid still works on the grid axis: grid-column-end: span 2 makes a card cover two columns, and cards with a definite position (grid-column: 2 / 4) are placed before the rest. If you define grid-template-rows instead of columns, the layout turns sideways and items flow into rows. There's also inline-grid-lanes for the inline-level version.
fit-tolerance: tightness against order
Here's the subtle part. If the browser always picked the strictly shortest column, a 2 px difference would send card 5 to the far left while card 4 sits on the right, and the reading order would zigzag for no visible benefit. So the spec treats columns whose heights are within a threshold of the shortest one as tied. Among tied columns, the browser takes the first one at or after an "auto-placement cursor", which points just past the previous card. In plain terms: when it doesn't matter much, keep going left to right.
That threshold is fit-tolerance:
.board {
fit-tolerance: normal; /* 1em in grid lanes layout */
fit-tolerance: 4em; /* tolerate bigger differences, keep more order */
fit-tolerance: infinite; /* strictly in order, ignore column heights */
}
The initial value, normal, resolves to 1em in grid lanes layout. infinite, according to the spec, makes items "distribute themselves strictly in order, without considering the length of the tracks at all", which can leave very uneven columns. Move the fit-tolerance slider in the demo and turn on "Tab order": the line connecting the cards in DOM order gets straighter as the tolerance grows, and the "cards out of turn" counter drops to zero.
The property used to be called flow-tolerance. The spec renamed it, and Safari 27.2 adopted fit-tolerance, keeping flow-tolerance as a deprecated alias. The 27.2 notes also explain why this matters beyond looks: a higher value keeps consecutive items in neighbouring columns, so keyboard focus moves more predictably.
Browser support and gotchas
-
Safari supports
display: grid-lanessince 26.4, according to MDN's compatibility data, andfit-toleranceunder its new name since 27.2. - Firefox has it only in preview builds. Chrome and Edge have no stable support: WebKit's January article said a variant had been behind a flag since version 140 and was being updated to the final syntax. MDN marks the feature as experimental and not Baseline.
- The fallback is one extra line. Browsers ignore values they don't understand, so declare a normal grid first:
.board {
display: grid;
display: grid-lanes;
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
gap: 10px;
}
Without support you get a regular grid with holes, which is perfectly usable. WebKit also suggests @supports not (display: grid-lanes) rules to crop images or truncate text so the grid fallback looks tidy, or loading a JavaScript masonry library only when CSS.supports('display', 'grid-lanes') is false. The demo does a version of the latter: in browsers without support, it runs the spec's placement algorithm in JavaScript. I checked it against WebKit's native rendering (Playwright's WebKit build) at seven tolerances and three column widths, and every card landed in the same spot.
-
Order and accessibility. The spec itself warns that this layout "can switch between endward in the inline or block axis in a seemingly arbitrary manner". Tab order follows the DOM, not the visual position. If the order of your cards carries meaning (a timeline, ranked results), raise
fit-toleranceor pick another layout. The spec points toreading-flowfor content without an inherent order, but that property is currently only in Chromium-based browsers. - The spec is still moving. The latest published Working Draft is from January 2026, and the Editor's Draft changed again in October. The spec even notes that the property that controls orientation is still to be decided.
What to keep an eye on
- When Chrome and Edge ship the final
grid-lanessyntax, not the flagged prototype. That's the moment this stops being a progressive enhancement and becomes a default. - Firefox moving it out of preview builds.
- Whether the orientation control and the other open issues in CSS Grid Level 3 change any syntax before then. For now,
display: grid-lanesplus adisplay: gridfallback is the safe way to use it.
Sources
- CSS Grid Layout Module Level 3 (Editor's Draft)
- Grid lanes layout - MDN
- WebKit Features for Safari 27.2 - WebKit blog
- When will CSS Grid Lanes arrive? How long until we can use it? - WebKit blog
Originally published at richi.codes.
Top comments (0)