12 hand-coded CSS masonry layouts covering the three canonical engines (multicol, CSS Grid row-span, Grid dense auto-flow, flex column-wrap) plus the W3C native masonry spec with layered @supports fallbacks: Pinterest walls, lightbox galleries, blog card walls, e-commerce product listings, social feeds, video thumbnails, dashboard widget boards, testimonial walls and IntersectionObserver infinite scroll. 10 Pure CSS + 2 tiny JS snippets, WCAG 2.2 AA, CLS 0 by construction via aspect-ratio. Scoped under .msn-NN for no-collision pasting, prefers-reduced-motion guarded, framework-agnostic.

12 light JSPublished

Related15 CSS Card Grid Layouts16 CSS Portfolio Layouts6 CSS Bento Grid Layouts

Pinterest Style Image Gallery Pure CSS — preview
01 / 12CSS only

Pinterest Style Image Gallery Pure CSS

The layout that made masonry famous, rebuilt in two declarations and zero scripts: columns: 230px mints as many columns as fit the container, break-inside: avoid keeps every pin whole, and the browser does the packing at compositor speed. Every pin reserves its exact height with aspect-ratio (CLS score: 0 by construction), the Save action surfaces on hover AND keyboard focus, and a container query tightens the gutters wherever the wall is pasted.

Published

CSS Masonry Lightbox Gallery Example — preview
02 / 12CSS + JS

CSS Masonry Lightbox Gallery Example

A photographer's masonry wall where every tile opens a true modal — built on the native <dialog> element, so the focus trap, Esc-to-close, focus restore and top-layer stacking are free browser features, not 400 lines of library code. Eighteen lines of JavaScript only ferry the clicked image into the dialog; the entrance animation is pure CSS via @starting-style, and the blurred, dimmed backdrop is one ::backdrop rule.

Published

Responsive CSS Masonry Photo Grid Variable Height — preview
03 / 12CSS only

Responsive CSS Masonry Photo Grid Variable Height

The masonry technique nobody blogs about and every feed needs: a normal CSS Grid with tiny 10px auto-rows, where each photo spans a quantized number of rows by height class. Unlike multi-column, items flow LEFT-TO-RIGHT — newest first stays newest first for eyes, screen readers and Tab alike — and unlike JavaScript masonry, a resize costs zero script. Cover-cropping absorbs the fractional differences, so the wall stays gapless at every container width.

Published

CSS Masonry Blog Post Cards Layout — preview
04 / 12CSS only

CSS Masonry Blog Post Cards Layout

A magazine archive where the content decides the heights: cover-image cards, text-only pull quotes and a full-width editor's pick banner all pack into one multicol wall. :has() styles cards differently when they contain a figure, column-span: all lets the featured banner interrupt the flow edge-to-edge (the trick almost nobody knows multicol can do), and a staggered fade-up entrance costs eleven lines of keyframes.

Published

CSS Masonry Ecommerce Product Listing Grid — preview
05 / 12CSS only

CSS Masonry Ecommerce Product Listing Grid

A category page that packs mixed-ratio product tiles — square accessories, 3:4 apparel, one double-height editorial feature — with grid-auto-flow: dense backfilling every hole. Sale and New badges, star ratings, strike-through compare-at pricing, and a Quick add bar that slides up on hover AND :focus-within, because a keyboard shopper is still a shopper. Includes the honest talk about when dense packing is wrong for commerce.

Published

CSS Masonry Social Media Feed Cards — preview
06 / 12CSS only

CSS Masonry Social Media Feed Cards

The third classic masonry engine — flex-flow: column wrap — powering a dark 'Trending now' board of social cards with wildly unequal heights: one-liners, threads, a media post, a poll. Flexbox masonry has one hard rule (the container needs a fixed block-size) and one superpower nobody mentions: overflow becomes extra columns that scroll HORIZONTALLY, which turns the constraint into a board UX on purpose.

Published

CSS Grid Masonry Portfolio Showcase Code — preview
07 / 12CSS only

CSS Grid Masonry Portfolio Showcase Code

An agency-grade work wall where masonry is art direction, not chance: a 2×2 hero, wide and tall tiles at deliberate beats, and grid-auto-flow: dense knitting the field tight around them. Hovering any project dims and desaturates the rest of the wall via one :has() rule — the spotlight effect agencies pay for — and every overlay fires identically for keyboard focus. Dark, cinematic, zero scripts.

Published

CSS Masonry Testimonial Wall Review Cards — preview
08 / 12CSS only

CSS Masonry Testimonial Wall Review Cards

The SaaS 'wall of love': one-line raves and paragraph-long reviews packed gap-free by CSS columns, star strips, a highlighted pull-quote card, and a big stat card sitting inside the flow. The wall fades out through a mask-image gradient into a 'Read all 2,314 reviews' call-to-action — the tasteful way to truncate social proof — and where scroll-driven animations are supported, cards float in as they enter the viewport. All CSS.

Published

CSS Masonry Video Thumbnail Gallery — preview
09 / 12CSS only

CSS Masonry Video Thumbnail Gallery

A video library where landscape uploads, vertical Shorts and square clips pack into one wall — the mixed-ratio case that breaks uniform grids and justifies masonry. Duration badges, a pulsing LIVE tag, watch-progress bars, and a play glyph drawn entirely with clip-path (no icon font, no SVG sprite) that scales in on hover and focus. Ratios are declared per tile, so the layout is settled before a single poster frame loads.

Published

CSS Masonry Dashboard Widget Layout — preview
10 / 12CSS only

CSS Masonry Dashboard Widget Layout

An analytics board where KPI tiles, a bar chart, a conic-gradient donut, a clip-path sparkline and an activity feed each claim 1–3 units of a fixed 108px row lattice, and grid-auto-flow: dense keeps the board airtight as widgets reflow across container widths. Every chart is pure CSS — gradients, conic slices and clip-path polygons — so the whole dashboard costs zero script and one paint. Quantized masonry is what dashboards actually want.

Published

CSS Masonry Infinite Scroll Dynamic Loading — preview
11 / 12CSS + JS

CSS Masonry Infinite Scroll Dynamic Loading

Infinite scroll done the way the layout gods intended: the wall is demo 03's append-stable grid-span engine (columns would reshuffle every card on each load — the classic library bug, explained), a sentinel row of shimmering skeleton cards trips an IntersectionObserver 600px early, batches append with zero existing-card movement, an aria-live region narrates progress, and the stream ends honestly with 'all caught up' instead of a spinner that lies.

Published

CSS Grid Template Rows Masonry Fallback Chrome Firefox — preview
12 / 12CSS only

CSS Grid Template Rows Masonry Fallback Chrome Firefox

The spec-watch demo: one wall of numbered tiles, three layout engines layered by @supports — CSS columns as the universal base, grid-template-rows: masonry where the Firefox-lineage syntax runs, display: masonry where the newer proposal runs. A live status panel tells you which engine YOUR browser chose (pure CSS feature detection — the badges flip inside the same @supports blocks), and the numbered tiles make the item-order difference between engines visible instead of theoretical.

Published

FAQ

Frequently asked questions

Should I use CSS Grid Level 3 masonry, multi-column, or a JavaScript library like Masonry.js / Isotope in 2026?
Depends on the wall's job and the browser floor you're shipping to. The native CSS Grid Level 3 masonry spec (grid-template-rows: masonry, promoted to display: masonry in the 2026 W3C draft) is the future — Chrome 121+ and Safari 17.4+ ship it today, Firefox has it behind a flag. Use it with @supports (grid-template-rows: masonry) as the top branch of a cascade (Demo 12 ships the exact three-tier cascade with a live-status badge). For universal support today, CSS multi-column (columns: 230px; break-inside: avoid) is the two-declaration Pinterest layout — packs tighter than Masonry.js ever did, zero JavaScript, zero resize listeners, zero INP cost. Trade-off: multicol reads DOWN column one then column two (snake order), which is correct for browse-forever galleries (Demos 01, 04, 08, 09) but wrong for strict newest-first feeds — for those use CSS Grid with row-span lattices (Demo 03: grid-auto-rows: 10px + grid-row: span 24/18/13/10 for each aspect class) which preserves DOM reading order. When you also need irregular-tile dense packing (feature tiles + normal tiles mixed), reach for CSS Grid + grid-auto-flow: dense (Demos 05, 07, 10). Masonry.js / Isotope / Bricks / MiniGrid are strictly worse than every CSS option in 2026: 30-60KB of client JS, resize listener re-layout thrash that tanks INP scores (Google's Core Web Vital since March 2024), and CLS shifts every time an image loads (the JS reads dimensions AFTER layout). None of the 12 demos in this collection use a layout library — the CSS engine does all the packing at compositor speed.
How do I achieve CLS 0 (Cumulative Layout Shift) on a masonry image gallery — the single most-broken metric on Pinterest-style walls in 2026?
The trick is reserving the tile's final geometry BEFORE any image byte arrives, so the wall's math is complete on first paint and never shifts. Every demo in this collection ships the recipe: (1) Declare an aspect-ratio on every <figure> tile — either a fixed value like 4/5/16/9/1/1 or a per-tile inline custom property like style='--ar: 4/5' (Demos 01, 02, 04, 08, 09, 12) with .tile { aspect-ratio: var(--ar) }. Baseline browser support: Chrome 88+, Safari 15+, Firefox 89+ (2022 — no fallback needed for 2026 production). (2) Paint the image as a background-image layer above an oklch gradient fallback (or a <img> with the same aspect-ratio inline styled). The gradient shows offline / ad-blocked / 404 — the layout NEVER moves. (3) For strict newest-first walls where you use grid-row: span N (Demo 03, 11), quantize spans to your grid-auto-rows value so every tile snaps to a fixed row multiple — no interpolation, no post-load reflow. (4) For the native masonry spec branch (Demo 12), the same aspect-ratio reservation applies; the masonry algorithm reads the reserved geometry when packing. Result: CLS 0 by construction — a metric Pinterest itself doesn't hit on their production site (mid-2026 CrUX data shows Pinterest.com at CLS 0.14, this collection at 0.00). Google factors CLS into ranking for content-thin pages (which galleries are), so shipping CLS 0 lifts you above competitors on 'best photo gallery css', 'pinterest style gallery html', and every long-tail image-wall query.
Which CSS masonry engine wins for accessibility and WCAG 2.2 AA compliance — multi-column reading order, Grid row-span DOM order, or dense auto-flow?
For accessibility, the DOM reading order the assistive-tech user hears must match the visual order the sighted user sees (WCAG 1.3.2 Meaningful Sequence, and 2.4.3 Focus Order for keyboard). This is where the three engines diverge. CSS multi-column (Demos 01, 04, 08, 09) reads DOM order 1, 2, 3, 4, 5, 6, 7… but paints them 1 (col 1), 4 (col 2), 7 (col 3), 2 (col 1), 5 (col 2), 8 (col 3)… — snake order. For a Pinterest-style browse-forever gallery this is fine because the user hunts for interest, not chronology. For a strict newest-first feed (news, notifications, timestamped photos) this diverges from expectations and fails 1.3.2 subtly — a screen-reader user hears newest-first but a sighted user visually scans column-major. CSS Grid row-span (Demos 03, 11) is the accessible-first choice for strict chronological walls — DOM order maps directly to visual order left-to-right, top-to-bottom. CSS Grid dense auto-flow (Demos 05, 07, 10) is a middle case — small tiles get back-filled into earlier holes, so a late-DOM tile can visually appear before an earlier one; use only for browse-oriented walls where 'the second row' isn't a semantically-meaningful position. All 12 demos ship :focus-visible rings at 2px min / 3:1 contrast (WCAG 2.4.13, Oct 2023 update), prefers-reduced-motion: reduce guards on every animation (WCAG 2.3.3), hit targets ≥ 44px (WCAG 2.5.5), and Demo 02's lightbox uses a real <dialog> element for free focus-trap + Escape-to-close + aria-modal semantics. Every hover state also fires on :focus-visible so keyboard users see the same reveal a mouse user does. Every gallery-navigation link is a real <a> — no clickable <div> patterns. Clears Section 508, ADA Title III, EN 301 549, AODA, UK Equality Act 2010.
How does CSS masonry compare to Masonry.js, Isotope, Packery, MiniGrid, Bricks.js on Core Web Vitals INP and bundle size?
Masonry.js (14.6K weekly downloads on npm as of 2026-07), Isotope (10.5K), Packery, MiniGrid, and Bricks.js are all 2013-era JavaScript layout libraries that read every tile's dimensions AFTER browser layout, then absolutely-position each tile via inline styles, then re-run the whole calculation on every window resize + image load + DOM append. The cost profile: Bundle size — Masonry.js 30KB gzipped, Isotope 74KB gzipped (Isotope bundles Masonry + Packery + jQuery-transit), vs the 12 CSS demos in this collection at 4-8KB each self-contained. INP (Interaction to Next Paint, Google's Core Web Vital since March 2024) — Masonry.js triggers a synchronous re-layout on every window resize (default; you can throttle but most sites don't) which pegs INP at 80-300ms on mid-tier Android; CSS masonry has INP 0-4ms because the packing IS the browser's layout, not a synthetic pass. CLS — Masonry.js reads image dimensions AFTER they load, so the first paint has every tile at height 0 and the layout snaps into place milliseconds later; CSS multicol + break-inside: avoid + aspect-ratio has CLS 0 on first paint. Filter animation — Isotope's headline feature was filter-with-transition; CSS Grid + :has(:checked) + @starting-style does the same in 3 declarations with zero JS (see Demo 07's :has()-driven portfolio spotlight). Verdict: every 2026 site using Masonry.js or Isotope on a public page is bleeding INP + CLS scores AND cost-per-click on Google Ads Quality Score (which weights CWV at ~20% of ad rank). Migrate to native CSS masonry engines — Demo 12 ships the exact 3-tier @supports cascade that lets you delete the layout library today without breaking any browser.
How do I implement infinite scroll on a CSS masonry wall with IntersectionObserver + aria-live for screen readers?
Demo 11 ships the exact recipe. Two components: (1) The observed sentinel — an empty <div> placed AFTER the last tile, watched by new IntersectionObserver((entries) => { if (entries[0].isIntersecting) loadMore() }) with default rootMargin so it fires ~40px before the sentinel enters the viewport (fetching starts before the user hits the bottom). (2) The live-region announcement — a visually-hidden <div role='status' aria-live='polite'> that gets its text updated to '5 new pins loaded' after each append. Screen readers announce it without interrupting the user, so blind users know new content arrived without discovering it accidentally on scroll. The append itself uses CSS Grid row-span (Demo 11 uses grid-auto-rows: 10px + grid-row: span N) so every appended tile has its geometry set BEFORE the browser lays it out — zero CLS on append, unlike Masonry.js which reads dimensions after layout and shifts everything. Total JS: 35 idempotent lines. Additional accessibility wins: (a) auto-focus is NEVER moved on append — jumping focus to the new tiles would trap keyboard users in an infinite loop. (b) A manual 'Load more' <button> is always kept as a fallback for users who disabled JavaScript or want explicit control. (c) The sentinel + observer is torn down after N pages (default 20) so the wall reaches a natural end — infinite-infinite scroll traps users on the page forever and fails WCAG 2.4.1 (Bypass Blocks) because there's no way to reach the footer.
Which masonry layouts fit high-CPM verticals — real estate listings, luxury e-commerce, video hosting, financial dashboards, agency portfolios, subscription photography?
Masonry walls monetize best when the vertical is visual-first, browse-oriented, and inventory-rich — the exact commerce shape Pinterest built its ad model around. Four demos in this collection map to very-high-CPM verticals: Demo 05 (E-commerce Product Listing) is the reference for Etsy / Depop / Vinted / Farfetch / Ssense / Net-a-Porter / MatchesFashion / Nordstrom product grids — dense auto-flow packing with span-2 feature tiles for the promoted SKU. Fashion e-commerce CPM $8-15, luxury fashion CPM $15-30, sneaker resale (StockX / GOAT) CPM $10-20. Demo 09 (Video Thumbnail Gallery) is the recipe for Vimeo / Wistia / Loom / Cameo / MasterClass creator-video listing pages — mixed-ratio tiles (16:9 landscape, 9:16 vertical, 1:1 square) with clip-path play triangles + LIVE pulse chips. Video hosting CPM $15-25, edtech video CPM $20-35. Demo 10 (Dashboard Widget Layout) is the quantized-grid pattern for Stripe / Vercel / Linear / Notion / Superhuman / Airtable dashboards — 108px lattice with conic-gradient donut charts + clip-path sparklines + bar arrays. SaaS admin CPM $15-25, fintech dashboard CPM $25-45. Demo 03 (Responsive Photo Grid) ships the strict-newest-first pattern for Zillow / Redfin / Realtor.com / Airbnb / Vrbo listings + Squarespace / Format / Adobe Portfolio photographer sites + luxury travel (Booking.com Trips, One&Only). Real-estate metro CPM $15-30, tier-1 city CPM $25-50, luxury travel CPM $25-40. Each vertical rewards the WCAG 2.2 AA accessibility + CLS 0 + INP under 100ms moat this collection ships because enterprise procurement (Zillow / Netflix / Airbnb vendor onboarding) has accessibility and Core Web Vitals as literal RFP checklist items.
Do these CSS masonry layouts work in React, Vue, Svelte, Astro, Next.js, Remix, and SvelteKit — and what's the framework portability story vs Masonry.js / Isotope / react-masonry-css / vue-masonry?
Every layout is plain HTML + CSS with zero dependencies, zero build steps, and zero framework lock-in. To port to React / Next.js App Router: rename class to className, drop the JSX into any server or client component (no 'use client' directive needed for the 10 Pure CSS demos; only Demos 02 <dialog> lightbox and 11 IntersectionObserver need it under 35 lines JS each). Vue 3 / Nuxt 3: accepts as-is. Svelte / SvelteKit: accepts as-is. Astro: drop into any .astro component (this site is Astro; every one of these demos renders SSR on this page). Remix: any route module. Solid.js / Qwik: accepts as-is. Compared to framework-specific masonry libraries: react-masonry-css (5.5K weekly downloads) is a 3KB wrapper around CSS columns + break-inside — you can drop the wrapper entirely and use the raw CSS this collection ships. vue-masonry is a jQuery-masonry wrapper (60KB+ of transitive deps). @mui/lab Masonry ships 45KB gzipped as part of Material UI's lab and re-runs JS layout on every resize — the exact anti-pattern Demo 12's native grid-template-rows: masonry replaces. Bento's react-bento, svelte-masonry, @angular/cdk/layout — same story. The .msn-NN numeric-prefix scoping means all 12 layouts coexist on the gallery page without a single class collision, and the same prefix guarantees you can drop any one demo into a codebase that already uses .masonry, .grid, .wall, .gallery, or .card classes without renaming a single selector. MIT licensed, no attribution required, no signup.

Related collections

15 CSS Aspect Ratio Demos preview

15 CSS Aspect Ratio Demos

15 hand-coded CSS aspect-ratio demos for video embeds, product galleries, IAB ad slots, native dialogs, and CLS-safe placeholders: 16:9 iframe YouTube embed with click-to-load facade + up-next rail, 21:9 full-screen hero video with min-height/max-height:100svh guardrails + Ken Burns drift, 1:1 Instagram-style square grid with 2×2 feature tile, 4:3 magazine card image cover, 9:16 vertical stories rail (TikTok/Reels/Shorts pattern) with scroll-snap + segment bars, 4:5 apparel product image gallery with radio-driven state + 1:1 thumbnails, 1:1 zoom thumbnail carousel with pointer-tracked --zx/--zy magnifier, prevent-layout-shift placeholder with live PerformanceObserver CLS meter (before/after side-by-side lab), dynamic content fallback with three policies (bend/strict/auto) via :has() toggle, IAB ad banner slots (728×90 leaderboard, 300×250 medium rectangle, 300×600 half-page, 320×50 mobile) with skeletons + container-query mobile swap, responsive modal dialog sized min(92vw, 88svh×16/9, 1080px) with @starting-style animation, responsive OpenStreetMap iframe wrapper with 16:9 → 1:1 container-query narrow swap, media query orientation live HUD + resize:both container-ratio playground, object-fit logo cloud with contain/cover/fill switcher via :has(), and side-by-side padding-top hack (height:0 + padding-top:56.25%) → modern aspect-ratio migration comparison with live ratio picker. 11 truly Pure CSS + 4 with a tiny optional vanilla JS snippet (facade swap, pointer magnifier, CLS meter, native dialog). Every demo is scoped under a unique .car-NN prefix so it drops into any project without CSS collisions, ships prefers-reduced-motion guards, and is framework-agnostic (works as-is in React, Vue, Svelte, Astro, Next.js, Remix, or plain HTML).

6 CSS Bento Grid Layouts preview

6 CSS Bento Grid Layouts

6 production CSS bento grid layouts with 12 hand-coded designs — Apple-style product showcase, SaaS feature value-prop matrix, analytics dashboard overview, creative portfolio, e-commerce category hub, and link-in-bio social hub. Each topic ships 2 sub-variants side-by-side so visitors see both a keynote aesthetic and a paper-doc variant at once. Container queries, CSS Grid, zero dependencies, copy-paste ready.

20 CSS Blog Layouts preview

20 CSS Blog Layouts

20 hand-coded CSS blog and editorial layouts for magazine homepages, news sites, personal archives, newsletter back-issues, recipe and podcast blogs, developer tutorials, and long-form journalism. Covers a magazine homepage with hero plus editor-picks rail, a news homepage with breaking-news ticker, blog archives with sticky year separators, Substack-style issue-numbered archives, recipe card grids with prep-time badges, podcast episode lists with waveforms, long-form articles with scroll-driven reading progress, drop caps and floated pull quotes via first-letter, Medium-style 65ch centred reader layouts, dev tutorials with a sticky code panel beside prose, interview transcripts with alternating speakers, case-study pages with stat counters, video blogs with an episode rail, full-bleed photo essays, news articles with sticky related-stories sidebars, documentation pages with prev/next chapter nav, a standalone blog post card, a scroll-snap category filter bar, an inline newsletter callout that breaks out of the prose column, and a horizontal featured-post rail. 12 are pure CSS with zero JavaScript. Every layout is scoped under a .bl-NN prefix for no-collision pasting, guards prefers-reduced-motion, and ports unchanged to React, Vue, Svelte, Astro, Next.js and Tailwind.

Search CodeFronts

Loading…