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.
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



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
alttext 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'salt. - 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.
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):
<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 / property | Default | Effect |
|---|---|---|
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
--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).