GooseUI

Components

Masonry Grid

New

A Pinterest-style layout for cards of different heights. Where the browser supports CSS Grid Lanes (display: grid-lanes), items go left to right into the shortest lane. Everywhere else the same markup falls back to multi-column layout. The browser picks the mode through @supports, so the component is a server component with no JavaScript at all.

Browser Support

Limited availability
2 features
Details
Grid lanes

Places items left to right into the shortest lane. Without it, the grid falls back to multi-column layout.

Your browser:
Multi-column layout

The fallback: items fill each column from top to bottom, so the reading order goes down the columns.

Your browser:

Preview

Numbers show the source order. With grid-lanes they run left to right, in the fallback they run down each column.

Active mode in your browser:columns fallback

  • 1

    Fog over Lake Bled

    Slovenia

  • 2

    Tram 28 at dusk

    Lisbon

  • 3

    Basalt columns

    Reynisfjara, Iceland

  • 4

    Tea terraces

    Munnar, India

  • 5

    Night market

    Taipei

  • 6

    Dune ridge

    Sossusvlei, Namibia

  • 7

    Glacier cave

    Vatnajökull, Iceland

  • 8

    Lavender rows

    Valensole, France

  • 9

    Harbor cranes

    Rotterdam

  • 10

    Rice paddies

    Bali

  • 11

    Old town roofs

    Dubrovnik

  • 12

    Aurora

    Tromsø, Norway

Installation

npx shadcn@latest add @gooseui/masonry-grid
pnpm dlx shadcn@latest add @gooseui/masonry-grid
yarn dlx shadcn@latest add @gooseui/masonry-grid
bunx --bun shadcn@latest add @gooseui/masonry-grid

Usage

import { MasonryGrid, MasonryItem } from "@/components/ui/masonry-grid"

export function Gallery({ photos }) {
  return (
    <MasonryGrid as="ul" minColumnWidth={220} gap={12} aria-label="Photos">
      {photos.map((photo) => (
        <MasonryItem as="li" key={photo.id}>
          <img src={photo.src} alt={photo.alt} className="w-full rounded-xl" />
        </MasonryItem>
      ))}
    </MasonryGrid>
  )
}

Examples

Notes wall

Text cards of very different lengths: the classic case for masonry. gap accepts any CSS length.

Retro action: move standup to 9:45 so the Berlin folks can join without skipping breakfast.

Priya

Ship the CSV export behind a flag first.

Marco

Customer interview takeaways: onboarding checklist is loved, but nobody finds the team invite link. Three out of five people asked where to add colleagues. Put it on the empty state of the members page and in the welcome email.

Lena

Who owns the staging certificate renewal? It expires Dec 3.

Tom

Design QA pass done for settings. Remaining: dark mode contrast on disabled inputs, focus ring on the avatar picker.

Aiko

Pizza Friday is back. Vote for toppings in #office by Thursday.

Sam

Postmortem draft for Tuesday's queue backlog is in the wiki. Root cause: retry storm after the DNS blip. Proposed fix: jittered backoff plus a circuit breaker on the webhook worker.

Jonas

Q1 OKR doc needs comments by Friday.

Priya

Bundle size dropped 38 KB after removing the date library. Thanks Lena for the Temporal polyfill idea.

Marco

<MasonryGrid minColumnWidth={200} gap="1.25rem">
  {notes.map((note) => (
    <MasonryItem key={note.id}>
      <article className="rounded-lg border p-4 text-sm">
        <p>{note.text}</p>
        <p className="mt-3 text-xs text-muted-foreground">{note.author}</p>
      </article>
    </MasonryItem>
  ))}
</MasonryGrid>

Narrow columns, wide gap

minColumnWidth sets the narrowest column. The number of columns follows the container width.

1120px
2200px
390px
4160px
5240px
6110px
7180px
8130px
9210px
10100px
11150px
12190px
<MasonryGrid minColumnWidth={140} gap={24}>
  {items.map((item) => (
    <MasonryItem key={item.id}>…</MasonryItem>
  ))}
</MasonryGrid>

Always columns

layout="columns" keeps the multi-column layout even where Grid Lanes is available, for example when the top-to-bottom order matters more than an even bottom edge.

1120px
2200px
390px
4160px
5240px
6110px
7180px
8130px
9210px
10100px
11150px
12190px
<MasonryGrid layout="columns" minColumnWidth={140} gap={24}>
  …
</MasonryGrid>

Props

PropTypeDefaultDescription
minColumnWidthnumber240Narrowest a column may get, in px. Columns stretch to fill the row
gapnumber | string16Space between items: number in px or any CSS length
layout"auto" | "columns""auto"auto picks Grid Lanes where supported, columns always uses multi-column layout
as"div" | "ul" | "ol" | "section""div"Rendered element, for example ul together with MasonryItem as="li"
classNamestring-Additional CSS classes

Components

ComponentDescription
MasonryGridThe container. Every direct child becomes a masonry item
MasonryItemOptional wrapper for one item: data-slot, block display and as (div, li, article, figure)

Features

  • No JavaScript: the layout is chosen in CSS through @supports, so it is ready on the first paint and never shifts after hydration
  • Semantic lists: as="ul" with MasonryItem as="li" keeps list semantics for screen readers
  • Tolerance: set --masonry-tolerance to tune how eagerly Grid Lanes keeps the source order (1em by default)
  • Overridable: the styles sit in @layer components, so Tailwind classes on the grid win