Lightbox
Photos one at a time, large, over the page: swipe or arrow between them, zoom in to look closer, close to go back to where you were.

Needs Alpine and the package's script. Without them the openers are plain links to the full photos, which is a working page. See getting started.
Use it
The easy way is photo grid's lightbox. On its own, mark
each opener with x-ds-lightbox and the lightbox's name, inside an Alpine
scope (any x-data), and render the lightbox once:
<div x-data>
@foreach ($photos as $photo)
<a href="{{ $photo->url }}" x-ds-lightbox="listing" data-ds-lightbox-caption="{{ $photo->caption }}">
<img src="{{ $photo->thumb_url }}" alt="{{ $photo->alt }}" width="160" height="120">
</a>
@endforeach
</div>
<x-ds::lightbox name="listing" :thumbnails="true" :original="true" />
x-ds-lightbox takes a name, not an expression. Its photos are every opener
of that name on the page, in document order, read when it opens: an opener
added later is included the next time.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
name | string | lightbox | Which openers it shows. |
label | string | Photo :n of :total | The dialog's name for each photo, followed by ": " and its alt. Translate it here. |
thumbnails | bool | false | A strip of thumbnails under the photo. |
original | bool | false | A link to the full image, in a new tab. |
download | bool | false | With original, the link downloads the file instead (same-origin images only; a browser rule). |
dismissible | bool | true | A swipe down closes it, as well as Escape and the close button. |
What an opener can carry:
| Attribute | What it does |
|---|---|
href | The full image. |
data-ds-lightbox-src | The full image, when href goes somewhere else. |
data-ds-lightbox-srcset | A srcset for the full image. |
data-ds-lightbox-alt | The alt, when the opener has no img inside. |
data-ds-lightbox-caption | A caption under the photo. |
The thumbnail is the img inside the opener, shown blurred while the full
photo loads.
How it behaves
- Moving: Left and Right (in the reading direction), Home and End, the arrow buttons, a swipe sideways, or a thumbnail. The photo slides in from its side; under reduced motion it just appears.
- Zoom: a click on the photo, a double tap, a pinch,
+and-, or the Zoom button, between fit and the photo's full size. Drag or use the arrows to look around it; the edges never come inside the frame. - Loading: if a photo takes more than 100 ms, its thumbnail shows blurred under a loader. A photo that fails says so, with Try again. The next and previous photos are fetched ahead.
- Closing: Escape, the close button, a press on the dark space around the photo, or a swipe down. Focus goes back to the tile of the photo you were last looking at, if it can be seen, or to the one you opened.
It is dark whatever the page's theme: photos are seen best on near-black.
Accessibility
- A modal dialog, on the same layer as modal: focus is held in it, the page behind does not scroll, and it stacks over other overlays.
- The dialog is named "Photo 2 of 12: Pine trees on a hillside", and the same is said politely on each move. The photo itself has its alt.
- Every gesture has a key or a button: there is nothing only a swipe does.
| Key | Does |
|---|---|
| Left / Right | The previous / next photo; when zoomed, look left / right |
| Up / Down | When zoomed, look up / down (Shift for further) |
| Home / End | The first / last photo |
+ / - | Zoom in / back to fit |
| Escape | Closes |
| Tab | Zoom, original, close, previous, next, the thumbnails (one stop; arrows inside) |
Don't
- Don't put the only copy of a photo's meaning in a caption. Put it in the alt, which is what the dialog is named by.
- Don't open it on a link to a page. The lightbox shows images; an opener
whose
hrefis a page needsdata-ds-lightbox-src. - Don't render two with one name. The first on the page is the one used.
More in specs/lightbox.md.
From the package repo: edit this page on GitHub.