Masonry

Masonry uses CSS Grid to create a masonry layout.

It is supported natively by Firefox; we polyfilled this behaviour with a little bit of JavaScript for other browsers.


Create Masonry layouts with CSS Grid

Just specify the number of columns and you’re good to go.

index.html
<div class="Masonry [--cols:2]">
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>

Span multiple columns

You can span an item across multiple columns with the --span property. (No other Masonry layouts on the internet lets you do this so easily).

index.html
<div class="Masonry">
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div class="[--span:2]">...</div>
<div>...</div>
</div>

Dense supported

Since we use CSS Grid, you can also use dense to pack smaller items upwards.

index.html
<div class="Masonry [--cols:3] dense">
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>

Make it responsive easily

Like SimpleGrid, you just have to change the --cols property at different breakpoints to make a responsive Masonry layout.

index.html
<div class="Masonry md:[--cols:2] lg:[--cols:3]">
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>
Resize to see this work!

Item-sizing supported

Instead of using --cols to determine the number of columns, you can let CSS Grid create intrinsic columns with Masonry-gallery and --item-width.

index.html
<div class="Masonry-gallery [--item-width:5rem] dense">
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>
Resize to see this work!

Waits for images and videos to load

Masonry waits for images and videos to load before it calculates the layout. This ensures your layout is accurate regardless of the content you contained within each grid item.