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

Wooden boardwalk trail through a sunlit pine forestWhite reindeer moss and lichen on a forest floor
VdImageBox Props
PropTypeDefaultDescription
srcstring"" Single-image thumbnail source when items is omitted.
fullSrcstring"" High-resolution lightbox image URL for single-image mode (falls back to src).
altstring""Accessible text description for single-image mode.
captionstring""Caption text for single-image mode.
itemsVdImageItem[][] 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.
columns2 | 3 | 43 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.
groupstring"" Lightbox group name stamped on data-image-box-group.
VdImageItem Interface
FieldTypeRequiredDescription
srcstringYesThumbnail image URL.
fullSrcstringNo Optional full-size image URL loaded when the lightbox opens (defaults to src).
altstringNo Accessible alt text copied to both the thumbnail and lightbox <img>.
captionstringNo 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 / EventSignature / ValueDescription
options.scrollThresholdnumber (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-boxTrigger attribute Marks an element inside root as a lightbox trigger.
data-image-box-full-srcstring Optional high-resolution image URL for the lightbox viewer.
data-image-box-captionstring Caption text shown in the lightbox (falls back to alt).
data-image-box-groupstring 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:openCustomEvent<{ src: string }> Bubbles from the trigger element when the lightbox opens.
imageBox:closeCustomEvent Bubbles from the trigger element when the lightbox closes.
imageBox:changeCustomEvent<{ index: number, total: number, src: string, trigger: HTMLElement }> Bubbles from the active trigger when opening or stepping through a group.
CSS Classes & Variables
Selector / VariableDefault / ScopeDescription
.vd-image-galleryGallery containerBase 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-triggerTrigger element Added automatically to initialized [data-image-box] elements; receives .is-active while selected and .is-broken if image loading fails.
.vd-image-box-backdropShared dialog overlay Ref-counted modal backdrop appended to document.body; toggled with .is-visible.
--vd-image-box-max-width85vw Maximum width of the enlarged image inside the lightbox.
--vd-image-box-max-height85vh Maximum height of the enlarged image inside the lightbox.
--vd-image-box-columns3 Number of columns in grid and masonry galleries.
--vd-image-box-gapvar(--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", and aria-label="Image viewer".
  • useFocusTrap traps Tab and Shift+Tab within the open viewer, and pressing Escape (or clicking the close button / backdrop) closes the dialog and restores focus to the trigger that opened it.
  • ArrowLeft and ArrowRight step backward and forward through triggers sharing the same data-image-box-group, updating the aria-live="polite" counter (.vd-image-box-counter) and setting aria-current="true" on the active thumbnail.
  • Non-interactive triggers (such as <img>) receive role="button", tabindex="0", keyboard activation on Enter / Space, and a default aria-label="View enlarged image" while preserving any custom aria-label already provided on the element.
  • Broken thumbnail images automatically receive the .is-broken fallback class on load error so failed assets stay visually identifiable.