Friday, December 19, 2025

Masonry Structure is Now grid-lanes


We’ve talked loads about Masonry format right here on CSS-Methods, so there’s no have to remind you of the two-sided discussions about how you can strategy it, the concept of utilizing it as a brand new unifying format idea, or various approaches for making it work at this time.

Right here’s what you do have to know: it’s going to be show: grid-lanes.

The earliest talks regarding masonry started in 2017 when Rachel Andrew expressed some issues about how you can make a Pinterest masonry format. Rachel mentioned it felt like the appropriate strategy needs to be a flexbox type of factor, however this wasn’t totally achievable with flexbox, as gadgets would fairly movement from top-to-bottom fairly than throughout every row:

At the moment the closest you may get with CSS to this sort of format is to make use of multi-col nevertheless, the gadgets then movement prime to backside fairly than throughout the rows.

This feels extra like a behaviour of flexbox than grid, as the answer may be very a lot based mostly on the scale of the gadgets. Opening this with a view to document the characteristic request/use case for future dialogue.

And so, the talks surrounding masonry format in CSS started throughout the W3C. In that very same GitHub thread, you’ll learn that Tab Atkins-Bittner shared a “hacky” strategy to go about it with CSS Grid.

You’ll be able to have Grid do Masonry if you recognize the heights of the gadgets forward of time. It’s a bit hacky, however you set the grid container to grid: auto-flow dense 1px / ;, then set every merchandise to grid-row: span ; (for instance, if the merchandise is 50px tall, use grid-row: span 50;).

I’m a sucker for intelligent CSS hacks, however you recognize what else I’m a sucker for? A working CSS resolution that makes it simpler for newbies to make use of. And no, sadly, we can not use grid-template-rows or grid-template-columns, as Nate Inexperienced advised in the identical thread:

.figure-list {
  show: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: movement;
}

Atkins-Bittner replied:

There’s no “easy” strategy to adapt Grid into Masonry – something would contain non-trivial edits to the format algorithm. Packery, specifically, actually wants issues to have an outlined width.

Okay, that’s high-quality. I’m certain you’d be pondering as properly, “why not create a brand new show property for it?” Properly, Rachel added that:

The factor is we will’t create a model new worth of show for each distinct design sample.

Thoughts you, all these discussions have been taking place way back to 2017, that means masonry has been an elusive aim for fairly a while.

Simply to be sure to’re with me, that is an instance picture of the type of format masonry appears to be like like (due to Michael Richins for this):

A series of nine green boxes arranged in three columns, each box with a large black number labeling their order in the layout.

One factor I would really like is that previous to the announcement of masonry show sort, there have been options/hacks mentioned, like this one from Andy Barefoot, however nothing really was determined as the principle go-to characteristic for CSS masonry. Hey, there was even an excellent cool Masonry library from David DeSandro, and he gave fairly helpful recommendation to W3C and browser distributors when writing the spec and implementing the masonry format, like on how loading photos would work, multi-column spanning gadgets, filling gaps, retaining horizontal order.

Take a look at the Masonry.js docs for extra details about the thing choices.

This thread helped, however it nonetheless didn’t result in a conclusive assertion about what the masonry syntax will seem like. In reality, we had code options, like from Dan Tonon:

.flex-container {
  show: flex;
  flex-direction: column;
  flex-block-count: 2; 
  flex-block-flow: cross; 
}

This introduces two new flexbox properties referred to as flex-block-count and flex-block-flow which permits us to regulate gadgets equally (with column-count) and management the movement of things, respectively. Nevertheless, this wouldn’t fly as Michael Richins identified:

It will nonetheless not work for youngsters of various peak…

This thread was not going anyplace, so discussions resulted in April 2020 with a GitHub consumer with the identify Nic787 referencing and agreeing with an earlier possible resolution for masonry utilizing float as a substitute of grid.

I believe you have got a very good level. At the moment, float is changing into previous and flexbox enable numerous issues to be accomplished, however this masonry format is missing in each.

… Generally you may have lot of small photos in a row, so making it left to proper can’t work on a regular basis. Masonry is left to proper like all the time, however in a means it’s simpler for the consumer to entry informations.

Luckily, discussions nonetheless continued in lots of threads, and the requests for the masonry show property flooded W3C. One other notable GitHub thread that surfaced on the masonry debate is, properly, the Masonry Syntax Debate in November 2024, however that additionally didn’t result in a lot at that time. In reality, Jen Simmons famous within the assembly that:

Personally disenchanted that we’re not making extra progress. We’ve been having this argument for five years.

5 years of backwards and forwards on how precisely the naming and construction can be. Can we use grid? Can we use a model new property? Can we create separate properties only for masonry? We couldn’t actually determine on that.

One factor I wish to get behind is a remark from our very personal Juan Diego, stating how options aren’t “simply use grid” or create a brand new property, however that we may eliminate the grid- prefix altogether and accept an choice that caters for each grid and masonry:

…it needs to be attainable to make use of a brand new unprefixed template-areas property for masonry and grid, whatever the formatting context..

Luckily, one thing good got here out of that thread as a result of one other assembly was held on January thirty first of 2025, and guess what? It was resolved to reuse grid templating and placement properties for masonry format.

The CSS Working Group simply mentioned [css-grid-3][masonry] Masonry Syntax Debate, and agreed to the next: RESOLVED: Re-use grid templating and placement properties for masonry format.

Wait. Why am I saying about masonry syntax properties? What about the principle syntax itself? Isn’t that why we’re right here? Superior, you’re nonetheless with me. So let me present you the precise thread the place the masonry syntax struggle ended.

It’s (virtually) right here!

This brings us to the newest announcement that setting grid-lanes on the show property prompts a masonry format.

.masonry {
  show: grid-lanes;
}

It was powerful to get right here. Deciding on the key phrase alone took years. Simply take a look at all the names that have been thought of main as much as grid-lanes:

  • collapsed-grid or grid collapse
  • grid-stack or stacked-grid
  • grid-pack or packed-grid or grid pack
  • compact-grid or compact grid
  • grid-masonry or masonry-grid
  • grid-flex or flex-grid
  • grid single-axis (masonry grid) vs. grid dual-axis (regular grid)
  • grid stack (masonry grid) vs. grid grid (regular grid)
  • staggered-grid or grid staggered
  • uneven-grid
  • semi-grid
  • lane-grid or grid-lanes
  • axial-grid

I wouldn’t have minded staggered-grid since that’s what it’s in React Native. In reality, Kevin Powell agreed. That mentioned, I’m completely okay with grid-lanes. It should take a while for browsers to implement it, as discussions surrounding the shorthand changes for masonry are nonetheless happening, with nothing a lot mentioned on the difficulty simply but.

What about Merchandise Circulate?

Oh yeah, do not forget that? It’s nonetheless within the works, and I count on that we’ll see it after a correct grid-lanes implementation begins making the rounds. There’s a pleasant hypothetical instance from Fantasai illustrating the way it may look if added to the spec at this time:

item-flow:  ||  ||  || 

/* shorthand for */
item-direction: row | column | row-reverse | column-reverse
item-wrap: wrap | wrap-reverse
item-pack: regular | dense || collapse
item-slack: 

In use, it could look one thing alongside the traces of:

.masonry {
  show: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  item-flow: collapse; /* == item-flow: row collapse 1em; */
  hole: 1rem;
}

So, what’s subsequent?

After many back-and-forths, masonry grid-lanes is right here! However the place precisely?

Properly, that is the awkward half. The reality is we’ll nonetheless have to attend for browsers to implement grid-lanes. How lengthy could it take? I actually can’t say, however consider that each one main browsers have already got applied some sort of masonry format behind flags or previews, however with completely different syntaxes:

So, excellent news throughout! All that’s left is to attend. If you wish to observe grid-lanes progress, right here is an efficient hyperlink pool for every browser from Patrick Brosset. And, when you can’t watch for the official masonry implementation, Zell Liew has an strategy for utilizing it at this time, with minimal JavaScript.

Related Articles

Latest Articles