# Grid Row-Span Masonry

> Masonry built on CSS Grid with tiny rows and per-item row spans, so items keep left-to-right order.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: masonry, grid, row span, reading order, pinterest
- Live preview: https://copy-css.com/snippets/grid-row-span-masonry
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="grid-masonry">
  <div style="--rows: 10"></div>
  <div style="--rows: 16"></div>
  <div style="--rows: 8"></div>
  <div style="--rows: 13"></div>
  <div style="--rows: 9"></div>
  <div style="--rows: 14"></div>
  <div style="--rows: 11"></div>
  <div style="--rows: 7"></div>
  <div style="--rows: 12"></div>
</div>
```

## CSS

```css
/* Each item spans --rows rows of 8px: set it from the item's height */
.grid-masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-auto-rows: 8px;
  column-gap: 16px;
}

.grid-masonry > * {
  grid-row: span var(--rows, 20);
  margin-bottom: 16px;
}
```

## Notes

- This CSS Grid Row-Span Masonry is 12 lines of pure CSS (0.3 KB) with no JavaScript and no dependencies. It uses CSS Grid and custom properties.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
