Lightbox
Full-screen media lightbox with carousel navigation
Source
LLM docs
Docs
Package
License
Installation
After installation import package styles at the root of your application:
Usage
@mantine/lightbox is a full-screen media lightbox built on embla carousel.
Click any image to open the lightbox:





Slide data
The slides prop accepts an array of LightboxSlideData objects. There are three slide types –
image (default), video and custom:
Image loading
By default, only the image of the active slide is loaded when the lightbox is opened, other images
and thumbnails are loaded lazily. Thumbnails use src if thumbSrc is not set, set thumbSrc
to a smaller image if the originals are large.
Set the loading property on an image slide to change this, for example to preload
the next slide:
Zoom
Enable image zoom with the withZoom prop. On desktop, click an image to zoom in, scroll wheel to
adjust zoom level, and drag or use arrow keys to pan when zoomed. On mobile, double-tap to zoom and
pinch to adjust. Use zoomMaxScale to change the maximum zoom scale (3 by default):





Click image to zoom, scroll to adjust, drag to pan when zoomed. Press Z to toggle zoom via keyboard.
Thumbnails
Set withThumbnails to display the thumbnail strip at the bottom. Users can hide it
with the T key or the toolbar button:





Custom thumbnails
By default, thumbnails are images. Set renderThumb on a slide to render custom thumbnail
content instead, for example a <video> element. The content is placed inside a 64x64px
button, size it with width: 100% and height: 100%:
All features
Zoom, thumbnails, fullscreen and download features can be combined:





Loop navigation
Set loop to enable infinite wrapping at the ends of the slide list:
Slide transition
By default, slides are changed instantly when arrow buttons or keyboard are used.
Set withSlideTransition to animate slide changes. Use emblaOptions={{ duration: 40 }}
to change the animation speed. Embla duration is not in milliseconds, values between 20 and 60
are recommended:
Embla options
Use emblaOptions prop to pass options to
the embla carousel. loop and startIndex options cannot be set this way, use loop and
currentIndex props instead:
z-index
zIndex controls the z-index of the overlay and the content elements, 400 by default:
Open and close transition
Use transitionProps to change the animation of the content, it accepts the same options
as the Transition component. The overlay always fades. To change only
the duration (200 by default), use transitionDuration:
Disable animations
Set transitionProps={{ duration: 0 }} to open and close the lightbox without animation:
Swipe to close
On mobile, swiping down closes the lightbox. This is enabled by default.
Set closeOnSwipeDown={false} to disable:
Click outside to close
Set closeOnClickOutside to close the lightbox when the empty space around the slide
content is clicked. It is disabled by default to prevent accidental closing:
Store API
Mount Lightbox.Provider once in your app and open the lightbox from anywhere
using the static Lightbox methods:
Multiple lightboxes
By default, Lightbox.Provider and the static Lightbox methods use the shared lightboxStore.
To use several independent lightboxes, create a separate store with createLightbox
and pass it to the store prop:
To subscribe to the state of any lightbox store in a component, use the useLightboxStore hook:
Video slides
Set type: 'video' on a slide to render a <video> element. Videos are paused
when the slide is changed. The poster image is used as the thumbnail unless
thumbSrc or renderThumb is set:
Opens on a video slide with autoPlay. Navigate away to see the video pause automatically.
Custom slides
Set type: 'custom' and a render function to display any content in a slide.
Custom slides do not have a default thumbnail, set renderThumb or thumbSrc:
Custom toolbar
Use toolbarItems prop to replace the default toolbar items. It accepts an array of items
or a function that returns it. The function is called with the lightbox state and handlers:
Use the built-in toolbar item factories for common actions:
Compound components
To change the layout of the lightbox, use compound components:
Lightbox.Thumbnails is rendered only when withThumbnails is set on Lightbox.Root.
Labels
Use labels prop to translate the lightbox. Labels that are not set fall back
to the default English values:
To change labels for all lightboxes in your application, set labels in
default props of the Lightbox component.
Accessibility
- Always set the
altproperty on image slides and thelabelproperty on video slides and custom toolbar items - The lightbox has
role="dialog"and is labelled withlabels.lightboxLabel, setaria-labelto change the label of a single lightbox - Focus is trapped inside the lightbox and is returned to the previously focused element when it is closed
- Slide changes are announced with
aria-live="polite" - Inactive slides are hidden from screen readers and removed from the tab order
Keyboard shortcuts
Set withKeyboardEvents={false} to disable all shortcuts except Escape. Shortcuts are ignored
while focus is inside an input, a video or an interactive element of a custom slide: