Skip to content
IndexRequest a UIAboutContact

Lightbox Image Viewer

A thumbnail grid opens a dark overlay viewer with previous, next, a counter, Escape to close and arrow-key navigation.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean UI mockup of an image lightbox: a near-black translucent backdrop over a photo grid, one large landscape photo centred with rounded corners, a circular close button at the top right, circular previous and next arrow buttons at the vertical middle on both sides, a small counter 3 / 6 below the image in white, flat modern style. Variants: the closed state with the thumbnail grid, and the first image with the previous button disabled. Negative: heavy chrome, text errors, watermarks, clutter. Reduced motion: static design.

About this pattern

Definition

A lightbox shows one image large over a dimmed page. It needs four things: a clear close button, previous and next controls that also work with arrow keys, a counter so people know where they are, and focus that stays inside until it closes.

Purpose & UX principles

  • Open from the thumbnail that was activated and return focus to it on close.
  • Arrow keys move between images; Escape and a click on the backdrop close.
  • Preload the neighbours so moving feels instant.

Interaction states

  • Six thumbnails, a viewer with Previous, Next and Close, and a counter.

Motion specification

  • The backdrop fades in over 150ms and images cross-fade over 200ms.
  • Reduced motion: no fades.

Responsive behaviour

  • On touch, add swipe; keep controls at least 44px.
  • Give every image a text description.

Code

HTML
<div class="bx" id="bx"><div class="gr" id="gr"></div><div class="lb" id="lb" role="dialog" aria-modal="true" aria-label="Image viewer" hidden><button class="x" id="cx" type="button" aria-label="Close">&times;</button><button class="n p" id="pv" type="button" aria-label="Previous image">&#8249;</button><div class="bg" id="bg"></div><button class="n q" id="nx" type="button" aria-label="Next image">&#8250;</button><span class="ct" id="ct"></span></div></div>

Related patterns

Modal Dialog

↗
Modal DialogOverlays & Dialogs

Drawer

↗
DrawerOverlays & Dialogs

Swipe Carousel

↗
Swipe CarouselGestures & Touch