Ir al contenido
Español

Cómo funciona

Unlike CSS columns, which fill top to bottom, each card goes to the top of the shortest column in turn, so the first cards stay at the top. Cards keep their DOM order and are placed with transforms from measured heights; a ResizeObserver remeasures when images load or text wraps. Before measuring (on the server and in the first frame) the grid falls back to a plain auto-fill grid, so it never renders empty.

Úsalo para

  • Galleries, moodboards and pins with mixed aspect ratios.
  • Cards whose text lengths vary a lot, such as notes or reviews.

Busca otra opción cuando

  • Items that must line up in rows for comparison: use a regular grid or table.
  • Thousands of items: pair it with paging, or use a virtual list.

Uso

import { MasonryGrid } from './MasonryGrid.jsx'

export function Gallery({ photos }) {
  return (
    <MasonryGrid
      label="Photos"
      items={photos}
      getKey={(p) => p.id}
      minColumnWidth={180}
      maxColumns={4}
      renderItem={(p) => <img src={p.src} alt={p.alt} width={p.width} height={p.height} style={{ width: '100%', height: 'auto' }} />}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
itemsT[]—The data, in reading order.
renderItem(item: T, index) => ReactNode—Renders one card at the column width; its height can be anything.
getKey(item: T, index) => Keyitem.id ?? indexA stable key, so a card keeps its measured height and glides instead of reappearing.
minColumnWidthnumber180Columns are added while each stays at least this wide.
maxColumnsnumber4Upper limit on columns.
gapnumber12Space between cards in px, both ways.
labelstring—Accessible name of the list.
...restHTMLAttributes<HTMLDivElement>—Passed to the root.

Accesibilidad

  • The root is role="list" and each card a listitem; DOM order equals data order, so screen readers and Tab follow the reading order, not the columns.
  • Focusable content inside cards keeps its own focus styles; the grid adds no keyboard traps.
  • Reduced motion removes the glide between layouts and shortens the fade-in to 160ms.

Movimiento

Cards fade in 40ms apart (up to twelve). When columns or heights change, cards move on a 560ms decelerating curve (cubic-bezier(0.2, 0.9, 0.25, 1)) and the grid height follows.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

MasonryGrid.jsxmasonry-grid.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Listas
Carrusel en arco viene con Pro. La vista previa aparece al desbloquearlo.
Carrusel cilíndrico viene con Pro. La vista previa aparece al desbloquearlo.