image-gallery

Thumbnail grid with lightbox viewer. Progressively enhances linked thumbnails into a fullscreen gallery with navigation, swipe, keyboard support, and View Transitions.

Overview

A thumbnail grid that opens a fullscreen lightbox viewer on click. Progressive enhancement at every layer: without JS, thumbnails are plain links to full images. With JS, a native <dialog> lightbox adds navigation, swipe, keyboard control, and View Transitions.

Uses the Invokers API (commandfor/command) for declarative close, and the Popover API (popovertarget) for caption details.

Usage

Image-only

Wrap each thumbnail in an <a> linking to the full image. The href is the full-size source; the <img> is the thumbnail.

With Captions

Wrap each item in a <figure> with a <figcaption>. Captions support HTML including links, and display in the lightbox via a popover panel.

Progressive Enhancement

LayerWhat works
HTML onlyGrid of linked images; click navigates to full image
HTML + CSSResponsive auto-fit grid, aspect-ratio thumbnails, hover zoom
+ InvokersDialog close button works declaratively
+ JSLightbox opens, navigation, keyboard, swipe, counter
+ View TransitionsThumbnail morphs into full image

Grid Configuration

Control the thumbnail grid layout with columns, gap, and ratio attributes.

Lightbox Navigation

  • Prev/Next buttons in the lightbox header
  • Keyboard: ArrowLeft/Right, Home/End, Escape to close
  • Swipe: Left/right touch gestures on the image area
  • Loop: Add loop attribute to wrap at ends

Counter displays "X of Y" and is announced to screen readers via aria-live.

Caption Modes

The captions attribute controls how <figcaption> content appears in the lightbox.

ValueBehavior
auto (default)Info button in header; toggles a popover panel via popovertarget
overlayPersistent caption bar below the image
hiddenCaptions suppressed in lightbox (still visible in grid)

Accessibility

  • Native <dialog> provides focus trapping, Escape-to-close, and ::backdrop
  • Close button uses commandfor/command="close" (Invokers API)
  • Counter uses aria-live="polite" for screen reader announcements
  • Prev/Next buttons have aria-label and disabled state at boundaries
  • All animations respect prefers-reduced-motion