Skip to content

Lightbox

Free

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.

  • Base UI
  • Motion
  • React 19
  • Tailwind CSS 4

Added Nov 15, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

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

trip-photos.tsx

Lightbox

PropTypeDefaultDescription
From Base UIDialog.RootBase UI docs

LightboxTrigger

<button>
PropTypeDefaultDescription
classNamestring—
indexRequirednumber—The item this trigger opens.
handle—A handle, for a trigger outside its Lightbox (createLightboxHandle).
From Base UIDialog.TriggerBase UI docs
idstring—ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialog in controlled mode (with the DialogRoot triggerId prop).
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

LightboxThumbnail

<div>
PropTypeDefaultDescription
srcSetstring—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.
widthnumber—The width of the box in px. With height, it sets the box ratio before the file loads.
heightnumber—
sizesstring—The sizes of the srcset: how wide the box is per screen ("(max-width: 640px) 100vw, 33vw").
loaderImageLoader—Makes the URL of each srcset width, Next.js style. Default: the loader of the nearest ImageLoaderProvider (none outside one).
transformerImageTransformer—An Unpic provider transformer, an alternative to loader.
qualitynumber—The quality that loader and transformer get (1–100).
preloadboolean—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—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).
blurDataURLstring—A tiny copy of the picture (10px or less, a data URL) for placeholder="blur".
placeholderColorstring—The main color of the picture for placeholder="color" (a data color).
positionstring—The CSS object-position of the picture in the box ("top", "30% 60%").
fadeboolean—Fade the file in when it loads. Default true. A file the page already loaded, or a server file, shows at once.
onLoadingStatusChange—Called with the new status: idle, loading, loaded, error.
onLoad—
onError—
classNamestring—The classes of the box (size, corners, ratio).
imgClassNamestring—The classes of the <img>.
styleCSSProperties—
childrenReactNode—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"—
srcstring | Blob—The file. Default: the item thumbnail, else its src.
altstring—Default: the item alt.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxContent

<div>
PropTypeDefaultDescription
classNamestring—
portalProps—Other Base UI props of the inner parts. A className here adds to the component classes.
backdropProps—
viewportProps—
From Base UIDialog.PopupBase UI docs
initialFocus—Determines the element to focus when the dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. - false: Do not move focus. - true: Move focus based on the default behavior (first tabbable element or popup). - RefObject: Move focus to the ref element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
finalFocus—Determines the element to focus when the dialog is closed. - false: Do not move focus. - true: Move focus based on the default behavior (trigger or previously focused element). - RefObject: Move focus to the ref element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
container—A parent element to render the portal element into.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxStage

<section>
PropTypeDefaultDescription
labelstring"Photos"The name of the slides region. Default "Photos".
...props<section> attributes—Every other attribute goes to the <section>, with a ref.

LightboxHeader

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxFooter

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxCounter

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxToolbar

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxZoomIn

<button>
PropTypeDefaultDescription
classNamestring—
busyboolean—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"—
labelstring"Zoom in"The accessible name. Translate it with the page.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

LightboxZoomOut

<button>
PropTypeDefaultDescription
classNamestring—
busyboolean—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"—
labelstring"Zoom out"The accessible name. Translate it with the page.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

LightboxSlideshow

<button>
PropTypeDefaultDescription
classNamestring—
busyboolean—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"—
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

LightboxFullscreen

<button>
PropTypeDefaultDescription
classNamestring—
busyboolean—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"—
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

LightboxDownload

<a>
PropTypeDefaultDescription
labelstring"Download"
...props<a> attributes—Every other attribute goes to the <a>, with a ref.

LightboxClose

<div>
PropTypeDefaultDescription
classNamestring—
labelstring"Close"
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxPrevious

<button>
PropTypeDefaultDescription
classNamestring—
labelstring"Previous photo"The accessible name. Translate it with the page.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

LightboxNext

<button>
PropTypeDefaultDescription
classNamestring—
labelstring"Next photo"The accessible name. Translate it with the page.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

LightboxCaption

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxTitle

<div>
PropTypeDefaultDescription
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxDescription

<div>
PropTypeDefaultDescription
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxThumbnails

<div>
PropTypeDefaultDescription
thumbnailLabellightboxThumbnailLabelThe name of one thumbnail button. Default "Show photo 5: Lake at dusk".
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxMain

<div>
PropTypeDefaultDescription
roombooleanfalseLeave 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).
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

LightboxPanel

<aside>
PropTypeDefaultDescription
openRequiredboolean—Shown. Keep it in the app (an Info button in the toolbar, the I key).
labelRequiredstring—The name of the panel region ("Info").
childrenReactNode—
...props<aside> attributes—Every other attribute goes to the <aside>, with a ref.
  • Use LightboxTrigger on each thumbnail.
  • Use LightboxContent children for your own layout of the parts.
  • Use createLightboxHandle for triggers outside the root.
  • For a row of slides on the page, use a Carousel.
  • For one picture with no viewer, use an Image.
Left ArroworRight ArrowGoes to the photo before or after.
HomeorEndGoes to the first or the last photo.
+or-or0Zooms in, zooms out, or resets the zoom.
EscCloses the viewer.

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.

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

Built with

Installs with Lightbox

  1. AddedLightbox, with Button, Image, Separator, Spinner.
Open the release