Image galleries
VdImageBox lays thumbnails out as a grid, masonry, bento, or filmstrip and opens a shared lightbox. Arrow keys, on-screen controls, and the useImageBox controller move through images that share a group. Escape or a backdrop click closes it and returns focus to the thumbnail.
Grid






Masonry






Bento





Filmstrip






Composable triggers
Any element with data-image-box inside the root opens the same viewer. You can also launch the viewer programmatically with box.open(index), call refresh() after adding images dynamically, or step an open viewer with next() / prev().


VdImageBox Props
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | "" | Single-image thumbnail source when items is omitted. |
fullSrc | string | "" | High-resolution lightbox image URL for single-image mode (falls back to src). |
alt | string | "" | Accessible text description for single-image mode. |
caption | string | "" | Caption text for single-image mode. |
items | VdImageItem[] | [] | Array of gallery image descriptors. Overrides single-image props when non-empty. |
layout | "grid" | "masonry" | "bento" | "filmstrip" | "single" | "grid" (or "single" for 1 item) | Gallery arrangement layout. |
columns | 2 | 3 | 4 | 3 | Column count for grid and masonry layouts (sets --vd-image-box-columns). |
gap | "fib-5" | "fib-8" | "fib-13" | "fib-21" | "fib-13" | Fibonacci spacing token applied via data-gap. |
ratio | "auto" | "1-1" | "4-3" | "16-9" | "3-4" | "golden" | "auto" | Thumbnail aspect ratio applied via data-ratio. |
captionDisplay | "lightbox" | "overlay" | "below" | "lightbox" | Where captions appear: only inside the lightbox, as a thumbnail hover overlay, or below each thumbnail. |
group | string | "" | Lightbox group name stamped on data-image-box-group. |
VdImageItem Interface
| Field | Type | Required | Description |
|---|---|---|---|
src | string | Yes | Thumbnail image URL. |
fullSrc | string | No | Optional full-size image URL loaded when the lightbox opens (defaults to src). |
alt | string | No | Accessible alt text copied to both the thumbnail and lightbox <img>. |
caption | string | No | Caption shown in the lightbox and optionally in overlay or below mode. |
orientation | "landscape" | "portrait" | "square" | No | Stamps data-orientation on the thumbnail for layout hints. |
useImageBox(root, options) Composable & Controller
| Member / Attribute / Event | Signature / Value | Description |
|---|---|---|
options.scrollThreshold | number (default 50) | Window scroll distance in pixels before an open lightbox automatically closes. |
open(target?) | (target?: HTMLElement | number) => void | Opens the lightbox for the given trigger element or zero-based index (defaults to 0). |
close() | () => void | Closes the active lightbox and restores focus to the trigger. |
next() / prev() | () => void | Steps forward or backward within the active image group (wraps around). |
refresh() | () => void | Re-scans root for newly inserted [data-image-box] triggers. |
data-image-box | Trigger attribute | Marks an element inside root as a lightbox trigger. |
data-image-box-full-src | string | Optional high-resolution image URL for the lightbox viewer. |
data-image-box-caption | string | Caption text shown in the lightbox (falls back to alt). |
data-image-box-group | string | Groups triggers inside the same root so arrow keys and next/prev step through them together. |
data-orientation | "landscape" | "portrait" | "square" | Optional aspect-orientation hint on the trigger element. |
imageBox:open | CustomEvent<{ src: string }> | Bubbles from the trigger element when the lightbox opens. |
imageBox:close | CustomEvent | Bubbles from the trigger element when the lightbox closes. |
imageBox:change | CustomEvent<{ index: number, total: number, src: string, trigger: HTMLElement }> | Bubbles from the active trigger when opening or stepping through a group. |
CSS Classes & Variables
| Selector / Variable | Default / Scope | Description |
|---|---|---|
.vd-image-gallery | Gallery container | Base wrapper rendered by VdImageBox. |
.vd-image-gallery-{grid|masonry|bento|filmstrip|single} | Layout modifier | Selects the grid, CSS column masonry, 5-tile bento, horizontal filmstrip, or single-image layout. |
.vd-image-box-trigger | Trigger element | Added automatically to initialized [data-image-box] elements; receives .is-active while selected and .is-broken if image loading fails. |
.vd-image-box-backdrop | Shared dialog overlay | Ref-counted modal backdrop appended to document.body; toggled with .is-visible. |
--vd-image-box-max-width | 85vw | Maximum width of the enlarged image inside the lightbox. |
--vd-image-box-max-height | 85vh | Maximum height of the enlarged image inside the lightbox. |
--vd-image-box-columns | 3 | Number of columns in grid and masonry galleries. |
--vd-image-box-gap | var(--vd-space-fib-13) | Grid and filmstrip gap token controlled by data-gap. |
Accessibility
- The shared lightbox backdrop renders with
role="dialog",aria-modal="true", andaria-label="Image viewer". useFocusTraptrapsTabandShift+Tabwithin the open viewer, and pressingEscape(or clicking the close button / backdrop) closes the dialog and restores focus to the trigger that opened it.ArrowLeftandArrowRightstep backward and forward through triggers sharing the samedata-image-box-group, updating thearia-live="polite"counter (.vd-image-box-counter) and settingaria-current="true"on the active thumbnail.- Non-interactive triggers (such as
<img>) receiverole="button",tabindex="0", keyboard activation onEnter/Space, and a defaultaria-label="View enlarged image"while preserving any customaria-labelalready provided on the element. - Broken thumbnail images automatically receive the
.is-brokenfallback class on load error so failed assets stay visually identifiable.