Skip to content

Lightbox

Preview Available in release assets

Enhance full-size image links with a native modal viewer.

Show code
<p><a href="product-large.jpg" data-lightbox-open="product-lightbox" data-media-index="0">Open full-size product image</a></p>
<dialog class="thin-dialog" id="product-lightbox" data-lightbox aria-labelledby="lightbox-title">
  <form method="dialog">
    <button class="thin-button" data-variant="secondary">Close</button>
  </form>
  <h2 id="lightbox-title">Product images</h2>
  <div data-lightbox-stage>
    <figure data-media-item>
      <img src="product-large.jpg" alt="Canvas tote, front view">
      <span data-image-fallback>Image unavailable. Close this viewer to use the original image link.</span>
    </figure>
  </div>
  <div data-media-controls>
    <button class="thin-button" data-variant="secondary" type="button" data-lightbox-zoom aria-pressed="false">
      <svg class="thin-icon" data-icon="zoom-in" viewBox="0 0 24 24" aria-hidden="true">
        <circle cx="11" cy="11" r="8" />
        <path d="m21 21-4.3-4.3M11 8v6M8 11h6" />
      </svg>
      <span>Zoom</span>
    </button>
    <output data-media-status>Image 1 of 1</output>
  </div>
</dialog>

Each authored example uses the production assets and includes copyable markup.

Anatomy

  • Original image link
  • Native dialog
  • Named stage
  • Close and zoom controls

Variants and sizes

  • Single image — shown above
  • Gallery — shown above

Rendered fixtures exercise authored content and constrained layouts with the same production assets.

  • Closed — shown above
  • Open — shown above
  • Zoomed — shown above
  • Image failure — shown above

Interaction and keyboard behavior

The original href works without JavaScript; enhancement opens a dialog, supports arrow navigation, and restores focus on close.

Accessibility

Use a labelled native dialog, meaningful image alternatives, real buttons, and an original destination link.

Contract
DIALOG
Basis
Native <dialog> and image/link fallback; no lightbox-specific APG role
Behavior guarantees
  • Uses native <dialog> and method="dialog"; the trigger helper only coordinates opening, initial focus, and return focus.
  • Rejects ambiguous or unnamed targets and keeps the authored link fallback when modal presentation is unavailable.
  • Focuses an available control on open and restores a connected trigger after close.
  • Clamps the media position and resets zoom.
Evidence
  • tests/unit/library/media.test.ts
  • tests/unit/library/advanced-component-contracts.test.ts

API

Use an anchor with data-lightbox-open pointing to dialog.thin-dialog[data-lightbox].

Behavior tier: dependency-free

Structured host, property, and example tables are not authored for this item yet. Use the summary above and the primary example.

Fallback

Every image remains an ordinary link or a natively scrollable figure without enhancement.

Assets and dependencies

  • /foundation.css
  • /layouts.css
  • /components.css
  • /behaviors.js

Dependencies: None

Source: packages/ui/src/items/media/style.ts

Composition

Derived from the examples and style specs, not authored.

Composes