GalleryPremium

Gallery Grid

A wall of thumbnails in columns where each photo keeps its own height, portrait or panorama, with no cropping; a click opens the full-screen viewer with a counter and arrows.

JSCSS ColumnsMasonryLightbox

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Gallery has 44 effects, including 6 free. Explore the category →

3 usage examples

Lighthouses photographed by the members of a coastal photo club — a wall of tall and wide photos — Gallery Grid example 1

① Lighthouses photographed by the members of a coastal photo club — a wall of tall and wide photos

WhenOn the “Lighthouses” page of the Penvorlec club, eight members' photos fill three columns to the right of the introduction: towers framed upright, coastlines framed wide, a sunset in a wide format. A click opens the photo, the arrow moves to the next one.
WhyA lighthouse shot upright and an islet seen from the air do not have the same shape; forcing them into one rectangle would cut the top off one or the shores off the other. The column wall leaves each the framing its author chose.
Settings--mlb-col: 100px, --mlb-cols: 3, --mlb-gap: 8px, --mlb-radius: 5px, --mlb-backdrop: rgba(6,14,20,.93), yellow --mlb-accent; 224 px thumbnails and 640 px large images in data-full. The scene removes the wrapper's background and padding to line it up with its page. In the capture, the mouse click opens the photo, then the scene clicks the real “next” arrow.
This week's finds in the side column of a mycology club's site — a two-column mini wall — Gallery Grid example 2

② This week's finds in the side column of a mycology club's site — a two-column mini wall

WhenTo the right of the Brévigny Mycology Circle's outing report, a 180 px box shows five members' photos in two narrow columns. You open one, then go through the others with the ← and → keys without leaving the article.
WhyIn a side column, five square thumbnails would take the whole height or be tiny. Two 75 px columns where each mushroom keeps its framing fit in 220 px of height and read at a glance.
Settings--mlb-col: 60px, --mlb-cols: 2, --mlb-gap: 6px, --mlb-radius: 4px, --mlb-backdrop: rgba(24,20,14,.94). No data-full: the viewer enlarges the thumbnail file (330 px wide, enough here). In the capture, the scene sends the dialog the → keys the script listens for.
Visuals in the press room of a garden festival — poster, banner and square in their true shape — Gallery Grid example 3

③ Visuals in the press room of a garden festival — poster, banner and square in their true shape

WhenThe press room of the Lourmelin Gardens offers four visuals: the upright poster, the very long web banner, a mood photo and the square for social networks. On a tablet, the journalist taps a visual to see it large, then swipes to compare the formats.
WhyHere the shape is the information: you must see at once that one visual is a poster and another a banner. The wall shows them at their real proportions, label included, and the viewer loads the heavy file only on demand.
Settings--mlb-col: 120px, --mlb-cols: 2, --mlb-radius: 6px, --mlb-backdrop: rgba(20,32,24,.93); 300 px thumbnails, larger files in data-full. The label (“Poster”, “Banner”…) is a <span> added inside each button by the scene. In the capture, the scene sends the image the finger swipe (pointerdown then pointerup) the script listens for.

How it works

The wall is built by the browser, with no maths. The rule columns: var(--mlb-col) var(--mlb-cols) asks for “columns at least 80 px wide, three at most”; each thumbnail is a <button> that takes the width of its column and the natural height of its image, and break-inside: avoid forbids cutting it in two. Measured on six images of different shapes: every button has exactly the proportion of its file (from 0.88 to 1.76).

Thumbnails flow like text in columns: down the first, then the second, then the third. The browser balances the heights and recomputes the number of columns to fit the room: three of 284 px in 900 px, three of 114 px on a 390 px phone, two of 80 px in a 200 px box.

Clicking a thumbnail opens a modal <dialog>: the large image (the data-full file if there is one, otherwise the thumbnail's), the “2 / 6” counter, two arrows that loop from the last to the first, and a dark blurred backdrop. Opening takes 0.4 s, with a slight bounce of the image. Each .fx-0174-root block has its own viewer: two walls on a page do not mix.

Accessibility

  • Keyboard: each thumbnail is a real button, reached with Tab (white ring, thumbnail enlarged by 5%) and opened with Enter or Space. In the viewer, ← and → change the image, Escape closes, and focus goes back to the thumbnail you started from (checked on the second wall of a page that holds two). Tab order follows the HTML, so down each column in turn.
  • Screen readers: the name of each button is the alt text of its image, so write it. The viewer is a named modal dialog; the counter is announced on every change (aria-live="polite") and the large image takes over the thumbnail's alt.
  • Touch: a tap opens, a horizontal swipe of more than 50 px on the image goes to the next or previous one (measured with an emulated finger in Chromium). Below 768 px, the 44 px arrows sit on the image: a swipe that starts on an arrow is not counted.
  • Reduced motion: no fade and no bounce, the viewer appears and disappears at once (open 60 ms after the click, closed 60 ms after Escape); thumbnails no longer grow on hover.
  • Page behind: while the viewer is open, the rest of the page is inert to clicks and keys, but the wheel still scrolls it (400 px measured in all three engines). To prevent that, add html:has(.mlb-viewer[open]) { overflow: hidden }: checked, no scrolling left.

Browser compatibility

Two native building blocks: CSS columns (columns, break-inside) for the wall, <dialog> and showModal() for the viewer, plus 4.3 KB of script with no dependency. Tried on 4 December 2026 on Chromium 149, Firefox 151 and WebKit 26.5: thumbnail proportions, click, arrows, looping, keys, click on the backdrop, focus return, mouse swipe, 390 px without overflow. In WebKit, the Tab key does not stop on the viewer's buttons (Safari's default setting); the ←, → and Escape keys work there.

Chrome 86+✓ Full (measured on Chromium 149)
Firefox 98+✓ Full (measured on Firefox 151)
Safari 15.4+✓ WebKit 26.5 engine measured, real Safari not verified
Edge 86+✓ Full (Chromium engine)
iOS Safari 15.4+✓ Not verified on a device
Android Chrome 86+✓ Emulated touch measured, real device not verified

The versions are those of <dialog> (Firefox 98, Safari 15.4) and :focus-visible (Chrome 86), according to MDN data. In a browser without showModal(), the script stops by itself: the wall shows, but clicking a thumbnail opens nothing. Without JavaScript, same result.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0174-root">
  <div class="mlb-grid">
    <button type="button" class="mlb-thumb" aria-haspopup="dialog" data-full="photo-1-large.jpg"><img src="photo-1.jpg" alt="What photo 1 shows" width="600" height="409"></button>
    <button type="button" class="mlb-thumb" aria-haspopup="dialog"><img src="photo-2.jpg" alt="What photo 2 shows" width="600" height="614"></button>
    <!-- … one thumbnail per photo … -->
  </div>
  <dialog class="mlb-viewer" aria-label="Image viewer">
    <div class="mlb-content">
      <p class="mlb-counter" aria-live="polite"><span class="mlb-current">1</span> / <span class="mlb-total">6</span></p>
      <button type="button" class="mlb-close" aria-label="Close"><svg>…</svg></button>
      <button type="button" class="mlb-nav mlb-prev" aria-label="Previous image"><svg>…</svg></button>
      <img class="mlb-image" alt="">
      <button type="button" class="mlb-nav mlb-next" aria-label="Next image"><svg>…</svg></button>
    </div>
  </dialog>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Photos (HTML — one <button class="mlb-thumb"> per image) six gradients (SVG in the code) Put in your images with their alt and, preferably, width and height so the columns do not jump while loading. The counter updates by itself.
data-full (on the button) absent Address of the large file shown in the viewer. Without it, the thumbnail image is the one enlarged.
--mlb-col 80px Minimum width of a column. The browser fits as many columns as there is room for, up to --mlb-cols.
--mlb-cols 3 Maximum number of columns. 2 for a side box or a phone, 4 or 5 for a wide page.
--mlb-gap 8px Space between thumbnails, across and down.
--mlb-radius · --mlb-radius-lg 0.5rem · 1rem Rounding of the thumbnails and of the large image.
--mlb-backdrop · --mlb-accent rgba(0, 0, 0, 0.9) · rgba(99, 102, 241, 0.3) Colour of the viewer backdrop, and of the drop shadow of a hovered thumbnail.

FAQ

The viewer is the same, script for script: counter, arrows, keys, swipe. What changes comes before the click. Lightbox with Navigation lines up identical thumbnails, 120 px wide in 3:2, where each photo is cropped to fill its slot. Gallery Grid arranges them in columns that take the full width, and none is cropped. Photos of mixed shapes: Gallery Grid. A uniform series or a row of attachments: the other one.
Top to bottom, column after column, like newspaper text: the first ones in the HTML fill the left column. Positions read on six images: 1 and 2 in the first column, 3 and 4 in the second, 5 and 6 in the third. If the reading order must go left to right, row by row (a ranking, a timeline), this wall is not the right tool.
With the original values, a 390 px screen still gets three 114 px columns, because three 80 px columns fit. Two ways to drop to two: --mlb-cols: 2 in a media query, or a larger minimum width, for example --mlb-col: 150px, which leaves room for only two columns below 500 px (measured: two columns at 490 px, three at 500).