Image viewer
The component supports mouse, touch, keyboard, and assistive technologies out of the box, with predictable navigation and motion-safe defaults.
Typical use cases:
-
Lightbox
A gallery of images that opens in a modal viewer when activated. -
Slideshow
A carousel that displays one image at a time, with navigation controls. -
Slideshow with lightbox
A slideshow where images also can be opened in a lightbox for a larger view.
Accessibility
Image Viewer 2 is built with accessibility in mind.
- Full keyboard navigation
- Screen reader support using
aria-live - Reduced motion support via
prefers-reduced-motion - Explicit labeling of slideshow containers using
aria-label
Automatic rotation and animated transitions are disabled or simplified when the user prefers reduced motion.
Lightbox
To enable the lightbox, add the data-zoom attribute to one or more links or buttons inside a container element. Initialize the container using JavaScript.
Activating any data-zoom element opens the lightbox and enables navigation between all data-zoom elements in that container.
Use href on links or data-href on buttons to specify the large version of the image.
-
Dry grass in sunlight
-
Bright green fern leaves
-
Two little snails on a green leaf
-
A close-up of a dandelion
Slideshow
Initializing the Image Viewer with the slides option turns the container into a slideshow (carousel).
All immediate child elements of the container are treated as individual slides. The container element should have an aria-label attribute.
Slideshow markup
- Each immediate child element of the container becomes a slide.
- The container should include an
aria-labeldescribing the slideshow content.
Slideshow with lightbox
Add the data-zoom attribute to enable the lightbox. Provide a larger image using data-href or href.
- Use
data-hrefwhen the slide element is a button or figure - Use
hrefwhen the slide element is a link
Optionally wrap the image in a link pointing to the larger image. The href attribute will be used for zoom and data-zoom must be added to the link, not the image.
Slideshow captions
To display captions in the slideshow, wrap images in a figure element and include a figcaption with the class env-image-viewer-2__viewer__caption.
Using figure is recommended, but captions can also be added to links.
Lightbox captions 2025.09.2
A figcaption placed inside a data-zoom element is automatically displayed in the lightbox.
Alternatively, use the data-figcaption attribute on an <img> to provide a caption that is only shown in the lightbox.
Configuration
Top-level options
| Option | Type | Description | Default value |
|---|---|---|---|
slides | bool | object | Enable slideshow behavior | false |
buttons.download | bool | Show download button in lightbox | true |
buttons.showText | bool | Show visible button labels | false |
i18n | string | object | Language or custom translations | "sv" |
Slides options
{
slides: {
auto: false,
transition: 'slide',
draggable: true,
playing: false,
autoHeight: false,
buttons: {
placement: 'overlay-top',
type: null,
ghost: false,
size: null,
}
}
}
| Option | Type | Description | Default value |
|---|---|---|---|
auto | number | Auto-rotation interval (ms), false disables | false |
transition* | string | slide, slideSlow, fade, none | "slide" |
draggable | boolean | Enable mouse drag navigation | true |
playing | boolean | Start auto-rotation automatically | false |
autoHeight* | boolean | Adjust height to current slide | false |
buttons.placement* | string | top, bottom, overlay-top, overlay-bottom | overlay-top |
buttons.type | string | Any Element color name in lowercase | null |
buttons.ghost | boolean | Use ghost button type | false |
buttons.size | string | Any Button size name in lowercase | null |
* = Option was added in 2026.02.1.
Options speed and overlay were deprecated in 2026.02.1, please use transition and buttons.placement instead.
API functions
Instances of Image viewer may be controlled by the methods described below.
Slider
-
slider.pause()- Pause slider automatic rotation.
-
slider.play()- Start slider automatic rotation if available.
-
slider.next()- Show next image.
-
slider.prev()- Show previous image.
-
slider.goTo(index, speed)- Set slider to image at position index. Use speed to control how fast image is shown.
-
slider.getPos()- Get index for current image.
Lightbox
-
lightbox.show(index)- Show lightbox starting at index. Defaults to index 0.
-
lightbox.close()- Close the lightbox.