Skip to content
WingoUI
ComponentsTemplatesDocsPricingAI agentsBlogChangelogContact
Components
Buttons & Actions
ButtonButton GroupCopy ButtonDelete ButtonTheme ToggleToggleToggle Group
Inputs
Avatar UploadCalendarCheckboxColor PickerComboboxCountry SelectCron PickerCurrency InputDate PickerDate Range PickerDate Time PickerDuration PickerEmail InputEmoji PickerFile UploadFilter BuilderInputInput GroupListboxMasked InputMention InputMonth PickerMulti SelectNumber InputOTP InputPassword InputPhone InputRadio GroupRatingSearch InputSegmented ControlSelectSignature PadSliderSwitchTag InputTextareaTime PickerTimezone SelectTree Select
Forms
Address InputBooking WidgetCSV ImportFieldForm WizardInline EditInvoice line itemsRich Text EditorSchema Builder
Navigation
Back To TopBounce SidebarBreadcrumbCommand MenuGlobal SearchGooey NavHook SidebarNav MenuNav TabsPaginationProximity SidebarScroll ProgressSidebarStepsTable Of ContentsTabsTopbarUser MenuWorkspace Switcher
Overlays
Alert DialogContext MenuDialogDrawerDropdown MenuFamily DrawerHover CardPopoverShare DialogSheetShortcuts DialogTooltipTour
Feedback
AlertBannerCookie ConsentEmoji ReactionEmpty StateNotification BellNotification CenterProgressRoute ProgressSetup ChecklistSkeletonSpinnerToast
Data Display
Approval FlowAvatarBadgeCalendar ViewCode BlockComment ThreadContact cardCountdownDescription ListDiff ViewerFile ListFile managerFolderGanttJSON ViewerKbdLog ViewerMarkdownPresenceSchedulerTagTimelineTree View
Tables & Lists
Audit LogData TableDeal PipelineEditable GridKanbanListMembers tablePermissions MatrixTableTask ListVirtual List
Charts & Stats
Animated CounterArea chartBar chartDonut chartFunnel chartGaugeGitHub ActivityHeatmap calendarLeaderboardLine chartRadar chartRadial barSparklineStat CardTrackerTrend badge
Layout
AccordionApp ShellCardCollapsibleDetail LayoutEntity HeaderPage HeaderScroll AreaSeparatorSettings LayoutSplit ViewToolbar
Media
Audio PlayerCarouselCSV ViewerDOCX EditorDOCX ViewerExcel ViewerFile SystemImage compareImage CropperImage GalleryImage LightboxLocation MapPDF ViewerPowerPoint ViewerQR CodeStep PlayerVideo Player
AI Kit
Agent Status CardChat MessageChat ThreadChat WidgetConversation ListFluid OrbGrid RevealMatrix OrbModel PickerPrompt InputReasoning IndicatorRule BuilderSuggestion ChipsTool Call TimelineUsage MeterVoice InputWorkflow Canvas
Text & Effects
Background PatternGravity LettersMarqueeTerminalText AnimateText Rotate
Mobile
Action SheetBottom Tab BarFABHaptic ButtonHero HeaderInstall PromptLarge Title HeaderNotification BannerOnboarding CarouselPicker WheelPull To RefreshSlide To ConfirmSticky CTA BarSwipe DeckSwipeable Tabs
Commerce
Cart drawerCategory pickerCheckout stepsCoupon inputFavorite buttonFilter panelListing cardListing gridOrder trackerPricePrice rangePricing tableProduct galleryQuantity stepperReviewsSeller card
Marketing Sections
App Download SectionBlog Cards SectionCTA SectionFAQ SectionFeature GridFeature ShowcaseHero SectionIntegrations SectionLogo CloudMarketing FooterMarketing HeaderMarketing SectionNewsletter SectionPricing SectionStats SectionSteps SectionTeam SectionTestimonials SectionTimeline SectionVideo Section
Blocks
Admin Dashboard PageAdmin ShellAI Chat PageAPI Keys PageAutomation Builder PageCheckout PageCRM Contact PageCRM Pipeline PageError PagesInbox PageInvoice PageKPI DashboardListing Detail PageLogin PageMarketplace Home PageMarketplace Search PageMarketplace ShellMobile App HomeOnboarding FlowOrder History PagePost Listing WizardPricing PageProfile PageRegister PageSettings PageUsers Admin Page
Templates
About PageAcademy PageAccessibility PageAffiliate PageAgency PageAI Product PageAppointment Booking PageBlog PageBlog Post PageBug Bounty PageCareers PageChangelog PageCommunity PageCompare PageContact PageCustomer Story PageCustomers PageDemo Booking PageDevelopers PageDocs Home PageDownload PageEnterprise PageEvents PageExperts PageFAQ PageFeature PageGlossary PageHelp Article PageHelp Center PageHome Services PageImpact PageIntegration Detail PageIntegrations PageJob Detail PageLanding PageLaunch PageLegal PageManifesto PagePortfolio PagePress PageProduct Tour PagePromo PageReal Estate PageReferral PageResearch Report PageRestaurant PageRoadmap PageROI Calculator PageSecurity PageSolutions PageStartups PageStatus PageStorefront PageSwitch PageTemplate Gallery PageTravel PageWaitlist PageYear in Review Page
Hooks & Utilities
AI ChatChart kitCommerceDate utilsFile exportFile typesFiltersForm validationHapticsInvoicingMotion presetsNavigationNumber formatRelative timeRomanian locationsSpreadsheetText matchTonesUIProvideruseClipboarduseConsentuseControllableStateuseCooldownuseDebounceuseKeyboardInsetuseLocaleuseLongPressuseMediaControlsuseMediaQueryuseOverflowItemsusePersistedStateuseScrollEdgesuseScrollStateuseSelectionuseShortcutuseStickToBottom
GalleryTheme

Media

Image Lightbox

Media

Image Lightbox React component for Tailwind CSS v4

Image GalleryLocation Map
Live props
State
defaultOpen
defaultIndex0
Behavior
loop
zoom
maxZoom4×
doubleTapZoom2.5×
swipeToClose
hideControlsDelay3000ms
Appearance
showThumbnails
showCaptions
showCounter
download
share
Code
import { ImageLightbox } from "@/components/ui/image-lightbox"

<ImageLightbox />
  1. Home
  2. Components
  3. Media
  4. Image Lightbox
Pro

Image Lightbox React component for Tailwind CSS v4

v1.0.0·Added in 1.0.0

A React image lightbox: a full-screen photo viewer that zooms from its thumbnail, with swipe, pinch zoom and swipe down to close.

Tap a thumbnail and the photo grows out of it into a black full-screen viewer (the thumbnail's crop opens up into the whole image); closing flies it back into the thumbnail of the photo you are on, or fades when that thumbnail is off screen. Swipe or drag sideways to move between photos (embla's physics, one photo per swipe); on a phone pull a photo down and it shrinks while the page shows through, then let go past a quarter of the screen or flick to close, or it springs back. Pinch to zoom around your fingers (it resists past 1x and the max, then settles), double-tap or double-click to zoom to the tapped point and again to go back, drag to pan a zoomed photo with momentum and a soft edge, and use ctrl or cmd + wheel (a trackpad pinch) to zoom at the cursor while a plain wheel pans; a horizontal trackpad swipe pages. While zoomed, swipes pan instead of paging and swipe-down is off; changing photo resets the zoom. On desktop the toolbar (counter, zoom level pill that resets on click, zoom out / in, download, share, close), the side arrows, the caption and the thumbnail strip fade after the idle delay and come back on any mouse move or key; on a phone a single tap toggles them, like Photos. Keys: Left / Right previous / next, Home / End first / last, + or = zoom in, - zoom out, 0 reset, Escape resets a zoom first and closes on the second press. Focus stays trapped in the viewer and returns to the thumbnail that opened it; the counter is a polite live region and the caption describes the dialog. Images load only near the current one, show a spinner (over the thumbnail as a placeholder) until ready and an icon when broken. Under reduced motion it fades instead of flying, and double-tap zoom jumps.

Image Lightbox is a Pro React component in the React media components category, written in TypeScript for React 19 and Tailwind CSS v4. It installs as source with npx wingo-ui@latest add image-lightbox, together with Carousel, Button, Spinner, useMediaQuery, useShortcut and 3 more and the npm packages @radix-ui/react-dialog, @radix-ui/react-visually-hidden, motion and lucide-react.

Add to a project

Requirements: React 19 and Tailwind CSS v4, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup

npx wingo-ui@latest add image-lightbox

Image Lightbox is part of Pro, with 298 more Pro items: $8 a month or $150 once. 14-day refund before you download any Pro item. See plans

Usage

Import ImageLightbox from @/components/ui/image-lightbox.

import { useState } from "react"
import { ImageLightbox, LightboxGallery, type LightboxImage } from "@/components/ui/image-lightbox"

const photos: LightboxImage[] = [
  { src: "/demo/apartment.jpg", alt: "Bright living room", caption: "Bright living room, 260 sq ft", width: 960, height: 600 },
  { src: "/demo/sofa.jpg", alt: "Velvet sofa", caption: "Velvet sofa, stays with the apartment", width: 960, height: 600 },
  { src: "/demo/laptop.jpg", alt: "Desk corner", caption: "Desk corner by the window", width: 960, height: 600 },
]

const labels = { dialog: "Photo gallery", download: "Save photo" }

// a grid of tiles; each photo zooms out of the tile you tap and back into it
export function ListingPhotos() {
  return <LightboxGallery images={photos} columns={{ base: 2, md: 3 }} download labels={labels} />
}

// one cover photo as the trigger, the index kept outside
export function CoverPhoto() {
  const [index, setIndex] = useState(0)
  return (
    <ImageLightbox
      images={photos}
      index={index}
      onIndexChange={setIndex}
      labels={labels}
      trigger={
        <button type="button" className="block overflow-hidden rounded-2xl">
          <img src={photos[index].src} alt={photos[index].alt} className="aspect-[16/10] w-full object-cover" />
        </button>
      }
    />
  )
}

Props

  • images*
    LightboxImage[]

    { src, alt, caption?, width?, height?, srcSet?, sizes?, thumbnail?, downloadName? }. width and height let the frame take the photo's shape before it loads (and let it fly from its thumbnail); thumbnail is the small file for the grid, the strip and the placeholder. An empty array never opens.

  • open
    boolean

    Controlled visibility. Pair with onOpenChange.

  • defaultOpendefault false
    boolean

    Opens on mount, uncontrolled. The playground opens the gallery at the first photo.

  • onOpenChange
    (open: boolean) => void

    Fires on open and on close (close button, Escape, swipe down).

  • index
    number

    The photo shown, controlled; out of range values clamp. Pair with onIndexChange to sync an outside strip.

  • defaultIndexdefault 0
    number

    The photo shown first, uncontrolled. The playground opens there with defaultOpen.

  • onIndexChange
    (index: number) => void

    Fires when the photo changes by swipe, arrow, key or thumbnail.

  • loopdefault false
    boolean

    Wraps from the last photo to the first (embla turns it off with too few photos).

  • zoomdefault true
    boolean

    Pinch, double tap / double click, ctrl or cmd + wheel (trackpad pinch), plain wheel to pan while zoomed, the +/- and 0 keys, and the zoom buttons (fine pointers).

  • maxZoomdefault 4
    number

    The largest scale, relative to the fitted photo. A pinch past it resists and settles back.

  • doubleTapZoomdefault 2.5
    number

    The scale a double tap or double click zooms to, centered on the tapped point (capped at maxZoom).

  • swipeToClosedefault true
    boolean

    Touch and pen: pull the photo down (while not zoomed) to close. It shrinks toward 0.85 and the black fades as it follows the finger; past a quarter of the screen or a quick flick it closes, else it springs back.

  • showThumbnailsdefault true
    boolean

    A synced strip under the photo from 640px up (phones have the counter instead).

  • showCaptionsdefault true
    boolean

    Each photo's caption at the bottom, on a gradient. It also describes the dialog for screen readers.

  • showCounterdefault true
    boolean

    The "3 / 8" counter at the top start, a polite live region.

  • downloaddefault false
    boolean

    A download button: a link with the download attribute (downloadName per image). Cross-origin files open instead.

  • sharedefault false
    boolean

    A share button that calls navigator.share with the photo's url; hidden where the browser has no share sheet.

  • hideControlsDelaydefault 3000
    number

    Desktop: the controls and the cursor fade after this many ms without a mouse move or key (never while a control is hovered or focused). 0 keeps them. Phones ignore it: a tap toggles them.

  • toolbar
    ReactNode

    Extra buttons at the start of the toolbar's action group, e.g. "Set as cover". Style them white: variant="ghost" with text-white hover:bg-white/10.

  • trigger
    ReactNode

    An element that opens the viewer at the current index (a Radix Dialog.Trigger with asChild); the photo zooms out of it.

  • getOrigin
    (index: number) => (Element | null | undefined)

    The element each photo flies out of and back into, usually its thumbnail (its first img gives the shape, its border radius the corners). Without one, or when it is off screen, the viewer fades and grows like a dialog. LightboxGallery wires it up.

  • container
    HTMLElement | null

    Portal target; document.body by default.

  • labels
    Partial<ImageLightboxLabels>

    Every string: dialog ("Image viewer", the hidden title), close, previous, next, zoomIn, zoomOut, resetZoom, download, share, counter(i, n) ("3 / 8"), loading, error, slide(i, n) ("3 of 8"), goTo(i), and for the gallery openImage(i, n, alt) and moreImages(n). English by default, DEFAULT_IMAGE_LIGHTBOX_LABELS.

  • classNames
    Partial<Record<"overlay" | "content" | "toolbar" | "counter" | "button" | "stage" | "slide" | "zoom" | "image" | "spinner" | "error" | "footer" | "caption" | "thumbnails" | "thumbnail" | "previous" | "next", string>>

    Extra classes for the inner parts.

  • className
    string

    Classes for the full-screen content. It carries the dark class on purpose: a photo viewer is black with white controls in both themes, like iOS Photos.

Parts

  • LightboxGallery

    component

    A grid of thumbnail buttons that opens the viewer and zooms out of the tapped tile. Defaults: columns { base: 2, sm: 3, md: 4 }, gap "md" (8px), aspect "square", radius "md" (12px; sm 8px, lg and full 16px), maxVisible 0 (all; otherwise the last tile says "+N"), featured false (the first tile spans 2 x 2). Broken thumbnails show an icon. With children it renders them instead of the grid, for custom triggers with useLightbox. Takes every ImageLightbox prop. Props: ImageLightboxProps & { columns?: number | { base?, sm?, md?, lg? }; gap?: "none" | "sm" | "md" | "lg"; aspect?: "square" | "4/3" | "16/10" | "auto"; radius?: "none" | "sm" | "md" | "lg" | "full"; maxVisible?: number; featured?: boolean; renderThumbnail?: (image, index, { hiddenCount }) => ReactNode; children?: ReactNode }.

  • useLightbox

    hook

    Custom triggers inside a LightboxGallery: open(2, event.currentTarget) zooms photo 3 out of the pressed element and returns focus to it. Signature: () => { open(index: number, origin?: Element | null): void; close(): void; index: number; isOpen: boolean }.

  • DEFAULT_IMAGE_LIGHTBOX_LABELS

    constant

    The English strings, to spread and override. Type: ImageLightboxLabels.

  • LightboxImage

    type

    One image: { src, alt, caption?, width?, height?, srcSet?, sizes?, thumbnail?, downloadName? }.

  • UseLightboxReturn

    type

    What useLightbox returns: { open(index, origin?), close(), index, isOpen }.

Examples

Listing hero grid

featured puts the first photo at 2 x 2; maxVisible={5} turns the last tile into +3.

Single hero image

A custom trigger with useLightbox: open(0, event.currentTarget) zooms the viewer out of the hero.

Download, share and a custom action

download with downloadName per photo, share where the browser has a share sheet, and a toolbar star.

Loop with controls always shown

loop wraps from the last photo to the first; hideControlsDelay={0} keeps the toolbar on desktop.

Chat attachments

Three photos in a message bubble open the viewer; the thumbnail strip is off.

Broken image

A missing file shows an icon in the grid and in the viewer, and never blocks swiping.

Controlled index

index and onIndexChange sync an outside strip; the big preview is the trigger and the origin.

Dependencies

@radix-ui/react-dialog@radix-ui/react-visually-hiddenmotionlucide-reactcarouselbuttonspinneruse-media-queryuse-shortcutuse-controllable-statemotionui-config

Files

  • components/ui/image-lightbox.tsx

FAQ

Is the React Image Lightbox component free?

The preview, props and docs are free; copying the source needs a Pro plan. See plans.

How do I install Image Lightbox?

Run npx wingo-ui@latest add image-lightbox. It also adds the Wingo UI items it builds on (Carousel, Button, Spinner, useMediaQuery, useShortcut and 3 more) and the npm packages @radix-ui/react-dialog, @radix-ui/react-visually-hidden, motion and lucide-react. With shadcn, add the @wingo-ui registry with your API key, then run npx shadcn@latest add @wingo-ui/image-lightbox.

How does Image Lightbox behave on phones?

Swipe or drag sideways to move between photos (embla's physics, one photo per swipe); on a phone pull a photo down and it shrinks while the page shows through, then let go past a quarter of the screen or flick to close, or it springs back.

See also

CarouselProduct galleryDialogFile ListCard

Used in

Product galleryFile managerReviewsFile SystemImage GalleryChat MessageInbox PageListing Detail PageRestaurant Page

More React media components

Video PlayerImage CropperLocation MapAudio PlayerExcel ViewerDOCX Viewer
All 17 React media components

Articles using this component

  • Nextjs Restaurant Template: Open Now, Menu, Book a Table

    Build it: screens and apps · Nov 6, 2026 · 10 min read

  • React Image Lightbox: Zoom, Swipe and Pull to Close

    Component guides · Oct 19, 2026 · 9 min read

PreviousImage GalleryNext Location Map

Northwind Homes · #NY-2026-0412

3-bedroom apartment, Brooklyn · Park Slope

840 sq ft · floor 3 of 8 · available Oct 1, 2026

$3,200/mo

Tap a photo. Pinch, double-tap or Ctrl / ⌘ + scroll to zoom; swipe down to close.

defaultIndex=0 · zoom=on · maxZoom=4× · doubleTapZoom=2.5× · swipeToClose=on · loop=off · hideControlsDelay=3000ms · thumbnails=on · captions=on · counter=on · download=off · share=off