Photo grid
Photos as tiles: an album, an attachment set, a listing's pictures. Equal squares, a masonry of columns, or justified rows of one height, with "+N" on the last tile when there are more than fit, and a lightbox to see them large.

No JavaScript needed for the grid: each tile is a link to its full photo.
lightboxneeds Alpine and the package's script; without them the tiles stay links. See getting started.
Use it
<x-ds::photo-grid
label="Trip to Skye"
:max="6"
:lightbox="true"
:photos="$photos->map(fn ($p) => [
'src' => $p->url, // the full image
'thumb' => $p->thumb_url, // what the tile shows
'alt' => $p->alt,
'width' => $p->width,
'height' => $p->height,
'caption' => $p->caption, // shown in the lightbox
])"
/>
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
photos | array | [] | The photos, in order. Arrays or objects; keys below. |
layout | grid masonry justified | grid | Equal tiles, CSS columns with each photo at its own shape, or rows of one height. |
columns | 1–6 | 3 | The most columns, reached as the grid's own container widens (grid and masonry). |
gap | sm md lg | sm | The space between tiles. |
ratio | square 4:3 3:2 16:9 3:4 | square | The tiles' shape, with layout="grid". |
max | int | — | Show at most this many tiles; the last says "+N" over it. |
moreHref | string | — | Where "+N" goes (the full album) instead of to its own photo. Without lightbox only: with one, "+N" opens it and the rest are a swipe away. |
rounded | bool | true | Rounded tiles. |
label | string | Photos | Names the list. |
lightbox | bool or string | false | true renders a lightbox for these photos, with thumbnails. A name wires the tiles to a lightbox of that name you render yourself. |
Per photo:
| Key | What it does |
|---|---|
src | The full image: what the tile links to and the lightbox shows. Required. |
alt | What the photo shows. Required unless decorative. |
thumb | The smaller image the tile shows. Defaults to src. |
width height | The full image's size, so the page does not shift as tiles load, and justified rows know each photo's shape. |
caption | Shown under the photo in the lightbox. |
href | Where the tile goes instead of the image, such as the photo's own page. |
srcset sizes | Passed to the tile's image. |
decorative | The photo adds nothing the text does not say: alt="", and the tile is named by its caption or position. |
A missing alt
With APP_DEBUG on, a photo with no alt that is not decorative throws,
naming the photo, so the gap is found while building. In production it logs
a warning and names the tile "Photo 3 of 8" rather than break the page.
One lightbox for several grids
<x-ds::photo-grid :photos="$before" lightbox="job-42" label="Before" />
<x-ds::photo-grid :photos="$after" lightbox="job-42" label="After" />
<x-ds::lightbox name="job-42" :thumbnails="true" :original="true" />
The lightbox shows every opener of its name on the page in order, so the reader goes from the last "before" to the first "after".
Accessibility
- A list named by
label; each tile is a link named by its photo's alt. - "+N" is drawn over the last tile and said as part of its name, ", and 4
more". The tiles past
maxare in the page, hidden, so the lightbox can show them, and out of the tab order. - The focus ring is drawn outside the tile, and the hover zoom on a tile is
motion-safe.
Don't
- Don't leave out
altto make the warning go away withdecorative: a photo that is the content needs words. - Don't send the full image as the tile. Give
thumb, andsrcsetwhere you have sizes, or the grid downloads every original. - Don't use it for icons or logos. It is for photos, cropped to fill.
More in specs/photo-grid.md.
From the package repo: edit this page on GitHub.