--- title: Image viewer description: Accessible image slideshows and lightbox galleries with flexible layout and predictable motion. ---
Örebro Castle
Karlslund Manor House
Highland cattle at Oset outside Örebro
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. ```html
``` ```javascript envision.imageViewer2( document.querySelector('#example-image-viewer-lightbox-only') ); ``` ## 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. ```html
Örebro Castle
Karlslund Manor House
Highland cattle at Oset outside Örebro
``` ```javascript envision.imageViewer2(document.querySelector('#example-image-viewer'), { slides: { auto: 3000, buttons: { placement: 'top', type: 'secondary', size: 'slim', }, }, }); ``` ### Slideshow markup - Each immediate child element of the container becomes a slide. - The container should include an `aria-label` describing the slideshow content. ```html noexample
Image description 1 Image description 2
``` ### Slideshow with lightbox Add the `data-zoom` attribute to enable the lightbox. Provide a larger image using `data-href` or `href`. - Use `data-href` when the slide element is a button or figure - Use `href` when the slide element is a link ```html noexample
Image description Image description
``` 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. ```html noexample
Image description Image description
``` ### 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. ```html noexample
Image 1 caption
Image 2 caption
``` ### 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 `` to provide a caption that is only shown in the lightbox. ```html noexample
Image 1 caption
``` ## Configuration ### Top-level options ```js { slides: false, buttons: { download: true, showText: false }, i18n: 'sv' } ``` | 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 ```js noexpand { slides: { auto: false, transition: 'slide', draggable: true, playing: false, autoHeight: false, buttons: { placement: 'overlay-top', size: null, type: null, // only placement top/bottom ghost: false, // only placement top/bottom } } } ``` | 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.size` | string | Any [Button size](/forms/button/#sizes) name in lowercase | `null` | | `buttons.type`_\*\*_ | string | Any [Element color](/colors/element-colors/) name in lowercase | `null` | | `buttons.ghost`_\*\*_ | boolean | Use [ghost button](/forms/button/) type | `false` |

* = Option added in 2026.02.1.

** = Options type and ghost not applicable for overlay placement.

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. ```javascript envision.imageViewer2('#image-viewer').then(function (imageViewers) { imageViewers[0].slider.pause(); imageViewers[0].lightbox.show(1); }); ``` ### 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.