Skip to content

MasonryGrid

XS, under 350B gzipped

A zero-JS masonry layout via CSS columns.

Category
Data display
Budget
xs, static display primitive
Runtime deps
None

Preview

Preview language
Card A
Card B

This is the exact fixture the conformance suite renders in CI. Switch the language to see the component mirror and reformat.

Install

npx shadcn@latest add https://kata-ui-rho.vercel.app/r/masonry-grid.json

Copies the source into your project. Pulls in 1 primitive: cn.

Source

import { cn } from "../lib/cn";

export interface MasonryGridProps {
  children: React.ReactNode;
  columns?: number;
  className?: string;
}

/**
 * CSS columns, not a JavaScript layout engine: this reflows correctly on
 * resize and under RTL for free (browsers already fill multi-column layouts
 * start-to-end, not literally left-to-right), and adds no runtime cost whatsoever.
 */
export function MasonryGrid({ children, columns = 3, className }: MasonryGridProps) {
  return (
    <div
      className={cn("gap-4 [&>*]:mb-4 [&>*]:break-inside-avoid", className)}
      style={{ columnCount: columns, columnGap: "1rem" }}
    >
      {children}
    </div>
  );
}

What CI checks

← All components