LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. Layout

Masonry layout

Also called masonry grid, Pinterest layout, or waterfall layout

A layout of columns where items of different heights stack tightly with no row lines, like stones in a wall or a Pinterest board.

import { useSyncExternalStore } from 'react';

type Photo = {
  id: string;
  url: string;
  alt: string;
  width: number;
  height: number;
};

function useColumnCount() {
  return useSyncExternalStore(
    (onChange) => {
      window.addEventListener('resize', onChange);
      return () => window.removeEventListener('resize', onChange);
    },
    () => (innerWidth >= 1024 ? 4 : innerWidth >= 768 ? 3 : 2)
  );
}

// Each photo goes into whichever column is currently shortest.
function toColumns(photos: Photo[], count: number) {
  const columns = Array.from({ length: count }, () => ({
    height: 0,
    photos: [] as Photo[]
  }));
  for (const photo of photos) {
    const shortest = columns.reduce((a, b) => (b.height < a.height ? b : a));
    shortest.photos.push(photo);
    shortest.height += photo.height / photo.width;
  }
  return columns.map((column) => column.photos);
}

export function PhotoBoard({ photos }: { photos: Photo[] }) {
  const columns = toColumns(photos, useColumnCount());

  return (
    <div className='flex gap-4'>
      {columns.map((column, index) => (
        <div key={index} className='flex min-w-0 flex-1 flex-col gap-4'>
          {column.map((photo) => (
            // width and height reserve each photo's space before it loads.
            <img
              key={photo.id}
              src={photo.url}
              alt={photo.alt}
              width={photo.width}
              height={photo.height}
              loading='lazy'
              className='h-auto w-full rounded-xl'
            />
          ))}
        </div>
      ))}
    </div>
  );
}
Show the inspiration board as a masonry layout: 4 columns on desktop, 3 on tablets, and 2 on phones with a 16px gap, placing each image in the shortest column so the order reads left to right. Reserve each image’s height from its aspect ratio so nothing shifts while loading, and fade items in with a 40ms stagger.

Paste into Layerwise or any AI coding tool.

What is Masonry layout?

In a masonry layout, each new item drops into whichever column is currently shortest, so tall and short items pack together without the gaps a regular grid leaves when items in a row have different heights. Columns stay aligned while rows stagger. It suits photos, pins, notes, and testimonials whose heights vary.

The order runs roughly left to right but hops between columns, so masonry is better for browsing than for content people read in sequence. Give items one fixed width, keep the gaps even, and reserve each image’s height up front with width and height or aspect-ratio so items do not jump as photos load.

CSS columns: 3 looks similar, but it fills the first column top to bottom before starting the next, which scrambles the order. Native CSS masonry is still rolling out across browsers, so most sites place items with a few lines of JavaScript or a small library.

Often confused with

Bento grid
A bento grid uses planned tile sizes that line up on a shared grid. A masonry layout accepts items of any height and packs them into columns.

Related terms

All terms

CSS Grid

A CSS layout system that places items on rows and columns at once, so content lines up in both directions.

Bento grid

A grid of rounded tiles in mixed sizes that fit together like a bento lunch box, often used to show several features at once.

Stagger

Animating a group of items one after another with a small delay between each, so they arrive as a cascade.

Lazy loading

A technique that waits to load images, videos, or code until they are about to scroll into view, so the first screen loads faster.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit
Masonry: no gaps
A winding road through yellow and orange trees, seen from above
Hot air balloons drifting over a rocky valley
Curved blue-and-white towers seen from below
A latte with leaf art in a white cup
A maroon canvas sneaker on a yellow background
A sand dune ridge under a clear blue sky
A dense carpet of red, yellow, and white flowers
Monstera leaves against a white wall