---
title: "Lightbox"
description: "A full-screen viewer for photos and videos. The thumbnail grows into the photo, people swipe or use arrows to move, pinch to zoom, and drag down to close."
url: https://gelatinui.com/components/lightbox
markdown_url: https://gelatinui.com/components/lightbox.md
access: free
install: "npx shadcn@latest add @gelatin-ui/lightbox"
registry_item: https://gelatinui.com/r/lightbox.json
version: "2026-11-15"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Lightbox

> A full-screen viewer for photos and videos. The thumbnail grows into the photo, people swipe or use arrows to move, pinch to zoom, and drag down to close.

Page: https://gelatinui.com/components/lightbox

## When to use it

Best for: The photos of a page: a press grows the thumbnail into a full-screen viewer with zoom.

- Use `LightboxTrigger` on each thumbnail.
- Use `LightboxContent` children for your own layout of the parts.
- Use `createLightboxHandle` for triggers outside the root.

## When not to use it

- For a row of slides on the page, use a [Carousel](https://gelatinui.com/components/carousel.md).
- For one picture with no viewer, use an [Image](https://gelatinui.com/components/image.md).

## Notes for agents

- `items` holds each photo with `src`, `alt`, `width`, and `height`.
- `type: "video"` adds a clip with native controls. It has no zoom.
- `disablePointerDismissal` stops a click next to the photo from closing it.
- `modal="trap-focus"` keeps focus inside and lets the page scroll.

## Anatomy

```text
Lightbox
├─ LightboxTrigger (0..n)
├─ LightboxThumbnail (0..n)
├─ LightboxContent (0..n)
├─ LightboxStage (0..n)
├─ LightboxHeader (0..n)
├─ LightboxFooter (0..n)
├─ LightboxCounter (0..n)
├─ LightboxToolbar (0..n)
├─ LightboxZoomIn (0..n)
├─ LightboxZoomOut (0..n)
├─ LightboxSlideshow (0..n)
├─ LightboxFullscreen (0..n)
├─ LightboxDownload (0..n)
├─ LightboxClose (0..n)
├─ LightboxPrevious (0..n)
├─ LightboxNext (0..n)
├─ LightboxCaption (0..n)
├─ LightboxTitle (0..n)
├─ LightboxDescription (0..n)
├─ LightboxThumbnails (0..n)
├─ LightboxMain (0..n)
└─ LightboxPanel (0..n)
```

## API reference

### Lightbox

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `readonly LightboxItem[]` |  | The photos and videos of the set, in order (`LightboxItem` from `#/lib/lightbox-state`). |
| `index` | `number` |  | The current item (controlled). |
| `defaultIndex` | `number` | 0 | The first item shown when the viewer opens with no trigger. Default 0. |
| `onIndexChange` | `function` |  |  |
| `loop` | `boolean` | false | After the last item, the next one is the first. Default `false`. It needs 3 items or more: with 2, the one neighbour would have to sit on both sides of the track at once, so a swipe would show an empty side and a change would come in from the wrong side. |
| `maxZoom` | `number` | 4 | The largest zoom (4 = 400%). Default 4. |
| `slideshowInterval` | `number` | SLIDESHOW_INTERVAL_MS | The time of one photo in the slideshow, in ms. Default 5000. |
| `handle` | `LightboxHandle` |  | Opens this Lightbox from triggers outside it (`createLightboxHandle`). |
| `labels` | `Partial<LightboxLabels>` |  | The words of the parts (`LIGHTBOX_LABELS`), in the page language. Keep the object stable. |
| `children` | `ReactNode` |  |  |

Also takes every prop of Base UI `Dialog.Root`: https://base-ui.com/react/components/dialog

### LightboxTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `index` | `number` |  | The item this trigger opens. |
| `handle` | `LightboxHandle` |  | A handle, for a trigger outside its Lightbox (`createLightboxHandle`). |

Also takes every prop of Base UI `Dialog.Trigger`: https://base-ui.com/react/components/dialog

### LightboxThumbnail

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `srcSet` | `string` |  | A ready `srcset` for `src` ("a-640.jpg 640w, a-1280.jpg 1280w"), with `sizes`: for files that a server already made at each width. It wins over `loader` and `transformer`. Change it together with `src`: the old picture keeps only its `src` while the new one loads. |
| `width` | `number` |  | The width of the box in px. With `height`, it sets the box ratio before the file loads. |
| `height` | `number` |  |  |
| `sizes` | `string` |  | The `sizes` of the srcset: how wide the box is per screen ("(max-width: 640px) 100vw, 33vw"). |
| `loader` | `ImageLoader` |  | Makes the URL of each srcset width, Next.js style. Default: the loader of the nearest `ImageLoaderProvider` (none outside one). |
| `transformer` | `ImageTransformer` |  | An Unpic provider transformer, an alternative to `loader`. |
| `quality` | `number` |  | The quality that `loader` and `transformer` get (1–100). |
| `preload` | `boolean` |  | A picture above the fold (a hero): loads at once with a high fetch priority, and React preloads it (`<link rel="preload">` with the srcset). Default `false`: lazy. |
| `placeholder` | `ReactElement \| ImagePlaceholderKind` |  | What shows while the file loads: `muted` (default, the muted box), `skeleton` (the box with a shimmer band), `blur` (`blurDataURL`, blurred), `color` (`placeholderColor`), `none` (no fill, also on an error: the parent shows), or an element: your own layer under the file until its fade ends (a sharp thumbnail of the same picture). |
| `blurDataURL` | `string` |  | A tiny copy of the picture (10px or less, a data URL) for `placeholder="blur"`. |
| `placeholderColor` | `string` |  | The main color of the picture for `placeholder="color"` (a data color). |
| `position` | `string` |  | The CSS `object-position` of the picture in the box ("top", "30% 60%"). |
| `fade` | `boolean` |  | Fade the file in when it loads. Default `true`. A file the page already loaded, or a server file, shows at once. |
| `onLoadingStatusChange` | `function` |  | Called with the new status: `idle`, `loading`, `loaded`, `error`. |
| `onLoad` | `function` |  |  |
| `onError` | `function` |  |  |
| `className` | `string` |  | The classes of the box (size, corners, ratio). |
| `imgClassName` | `string` |  | The classes of the `<img>`. |
| `style` | `CSSProperties` |  |  |
| `children` | `ReactNode` |  | An `ImageFallback` for the error and the no-`src` box. Default: an icon (none for `alt=""`). With a child, the root is not `role="img"`: the fallback speaks for itself, and an img role would hide its words and controls (a retry button) from screen readers. |
| `fit` | `"contain" \| "cover"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `src` | `string \| Blob` |  | The file. Default: the item `thumbnail`, else its `src`. |
| `alt` | `string` |  | Default: the item `alt`. |

### LightboxContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `portalProps` | `Omit` |  | Other Base UI props of the inner parts. A `className` here adds to the component classes. |
| `backdropProps` | `Omit` |  |  |
| `viewportProps` | `Omit` |  |  |

Also takes every prop of Base UI `Dialog.Popup`: https://base-ui.com/react/components/dialog

### LightboxStage

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | "Photos" | The name of the slides region. Default "Photos". |

### LightboxHeader

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### LightboxFooter

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### LightboxCounter

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### LightboxToolbar

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### LightboxZoomIn

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `label` | `string` | "Zoom in" | The accessible name. Translate it with the page. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### LightboxZoomOut

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `label` | `string` | "Zoom out" | The accessible name. Translate it with the page. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### LightboxSlideshow

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### LightboxFullscreen

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### LightboxDownload

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | "Download" |  |

### LightboxClose

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `label` | `string` | "Close" |  |

### LightboxPrevious

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `label` | `string` | "Previous photo" | The accessible name. Translate it with the page. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### LightboxNext

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `label` | `string` | "Next photo" | The accessible name. Translate it with the page. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### LightboxCaption

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### LightboxTitle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

### LightboxDescription

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

### LightboxThumbnails

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `thumbnailLabel` | `function` | lightboxThumbnailLabel | The name of one thumbnail button. Default "Show photo 5: Lake at dusk". |

### LightboxMain

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `room` | `boolean` | false | Leave room for an open `LightboxPanel` at the inline end (on a screen of 768px and wider; a phone shows the panel as a sheet over the photo, so the room stays 0). |

### LightboxPanel

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` |  | Shown. Keep it in the app (an Info button in the toolbar, the I key). |
| `label` | `string` |  | The name of the panel region ("Info"). |
| `children` | `ReactNode` |  |  |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Lightbox | `lightbox` |  |  |  |
| LightboxTrigger | `lightbox-trigger` | `data-disabled` |  | `motion-timing` |
| LightboxThumbnail | `lightbox-thumbnail` |  |  | `motion-timing` |
| LightboxContent | `lightbox-content` |  | `--lightbox-opacity` |  |
| LightboxStage | `lightbox-stage` | `data-zoomed` | `--lightbox-fit-center`, `--lightbox-scale`, `--lightbox-x`, `--lightbox-y` |  |
| LightboxHeader | `lightbox-header` | `data-chrome`, `data-presence`, `data-zoomed` |  | `motion-timing` |
| LightboxFooter | `lightbox-footer` | `data-chrome`, `data-presence`, `data-zoomed` |  | `motion-timing` |
| LightboxCounter | `lightbox-counter` |  |  |  |
| LightboxToolbar | `lightbox-toolbar` |  |  | `hit-area` |
| LightboxZoomIn | `lightbox-zoom-in` |  |  |  |
| LightboxZoomOut | `lightbox-zoom-out` |  |  |  |
| LightboxSlideshow | `lightbox-slideshow` | `data-playing` | `--lightbox-ring` |  |
| LightboxFullscreen | `lightbox-fullscreen` | `data-active` |  |  |
| LightboxDownload | `lightbox-download` |  |  |  |
| LightboxClose | `lightbox-close` |  |  |  |
| LightboxPrevious | `lightbox-previous` |  | `--lightbox-fit-center` |  |
| LightboxNext | `lightbox-next` |  | `--lightbox-fit-center` |  |
| LightboxCaption | `lightbox-caption` |  |  |  |
| LightboxTitle | `lightbox-title` |  |  |  |
| LightboxDescription | `lightbox-description` |  |  |  |
| LightboxThumbnails | `lightbox-thumbnails` |  | `--lightbox-ring-index` | `motion-timing`, `scroll-fade` |
| LightboxMain | `lightbox-main` |  | `--lightbox-room` |  |
| LightboxPanel | `lightbox-panel` |  |  |  |

## Usage

Give it the items, a trigger per photo, and the content.

```tsx title="trip-photos.tsx"
import { Lightbox, LightboxContent, LightboxTrigger } from "@/components/media/lightbox";

const PHOTOS = [
  { src: "/lake.jpg", alt: "A boat on a lake", width: 1600, height: 1067, title: "Lake" },
  { src: "/ridge.jpg", alt: "A ridge above the clouds", width: 1600, height: 1067, title: "Ridge" },
];

export function TripPhotos() {
  return (
    <Lightbox items={PHOTOS}>
      <LightboxTrigger index={0}>Open the photos</LightboxTrigger>
      <LightboxContent />
    </Lightbox>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/lightbox
```

It adds 57 registry items: 52 files, 11318 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@phosphor-icons/react`, `@unpic/core`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Button](https://gelatinui.com/components/button.md)
- [Image](https://gelatinui.com/components/image.md)
- [Separator](https://gelatinui.com/components/separator.md)
- [Spinner](https://gelatinui.com/components/spinner.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Carousel](https://gelatinui.com/components/carousel.md)
- [Image](https://gelatinui.com/components/image.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Left Arrow, Right Arrow | Goes to the photo before or after. |
| Home, End | Goes to the first or the last photo. |
| +, -, 0 | Zooms in, zooms out, or resets the zoom. |
| Esc | Closes the viewer. |

## Accessibility

It is the Base UI Dialog: focus stays inside, and Escape closes it.

Focus returns to the thumbnail of the photo the person ends on.

The dialog takes its name from the title or the `alt` of the photo.

## Motion

| Part | Motion |
| --- | --- |
| Open | sheet · 300ms · ease-panel (0.2, 0.4, 0.2, 1) · the thumbnail grows into the photo |
| Close | sheet · 300ms · ease-panel (0.2, 0.4, 0.2, 1) · the photo flies back to its thumbnail |
| Open with no thumbnail | overlay · 200ms · ease-panel (0.2, 0.4, 0.2, 1) · fades in and scales from 95% |
| Close with no thumbnail | overlay-exit · 150ms · ease-out (0, 0, 0.2, 1) |
| Slide change | sheet · 300ms · ease-panel (0.2, 0.4, 0.2, 1) · the track glides to the next photo |
| Swipe and drag release | sheetRelease · 300ms · no bounce · keeps the speed of the finger |
| Bars | fade · 150ms in, fade-exit · 90ms out · ease-out (0, 0, 0.2, 1) |
| Strip ring | indicator · 200ms · ease-panel (0.2, 0.4, 0.2, 1) · moves to the current thumbnail |
