Lightbox
A full-screen viewer for a gallery of images, opened from a thumbnail and zoomable up to 4x.
<arc-lightbox>Overview
Lightbox shows a gallery of images at full screen, above the page behind a blurred backdrop. It shares the overlay infrastructure with Dialog and Sheet: focus is trapped while open, page scroll is locked, Escape and a backdrop click dismiss, and focus returns to the trigger on close. Open it from a thumbnail with show(index), or set open and index directly.
There are two ways to give it pictures. Set the images property to an array of src strings or { src, alt, caption, srcset, sizes, width, height } objects, and one array can mix the two. Or set gallery to a selector for links already on the page, such as gallery="#photos a". Each matched <a href> becomes an entry, with alt text from the image inside it and a caption from data-caption. A click on one opens the viewer on that picture. The links are read at click time, so ones added later are included, and without JavaScript they still open the full-size image.
Stepping wraps at both ends. Move with the arrow buttons, the arrow keys, Home and End, or a sideways swipe on touch. Each step fires arc-change with the new index in detail.value, and the images either side of the current one are fetched ahead so a step shows at once. A slow image gets a spinner after 150ms, and one that fails shows a short message and its alt text instead of a broken picture.
Zoom runs from 1x to 4x. Pinch or Ctrl + wheel zooms toward the fingers or the pointer, a double-click or double-tap zooms to 2x at that spot, and +, - and 0 step and reset it. While zoomed, dragging and the arrow keys pan, and the image's edges never come inside the frame. Stepping to another image or closing resets the zoom.
Opened from a thumbnail, the picture grows out of it, and on close it shrinks back into the thumbnail of whichever image is showing. Each step slides the picture a short way in the direction of travel. Under reduced motion both become a plain fade. A gallery link is the thumbnail for its own image. With the images property, the first image grows from whatever was clicked or focused when show() ran, and an entry's origin (an element or a selector) sets the thumbnail for any image.
Add thumbnails for a filmstrip under the picture. It stays faint until you point at it or tab into it, marks the current image with a short glowing bar, and jumps on click. An entry's thumb gives it a small source; otherwise the strip uses src, loaded lazily.
The top bar and the arrows fade after a few seconds without movement, and come back on any pointer movement, key press or tap. They stay while a keyboard user has focus in them. The actions slot adds your own buttons to the bar, for download or share.
next(), prev() and close() drive the viewer from outside, with the same events as the built-in controls. arc-close is cancelable on every path, including a swipe down and a programmatic close(), so a veto always holds.
Guidelines
Do
- Use it for photo galleries, screenshots and other images worth seeing at full size
- Prefer `gallery` when the thumbnails already link to the full images
- Open it from a visible thumbnail so the viewer starts on the image the reader chose
- Give every entry `alt` text. It also labels the dialog and is read out on each step
- Add `thumbnails` for galleries longer than a handful of images, where stepping one at a time is slow
- Pass `width` and `height` when you know them, so the frame holds its shape while the image loads
- Use `caption` for attribution or context that should travel with the image
Don't
- Don't use it for anything but images. Use Dialog
- Don't open it on page load. Let the reader choose a full-screen view
- Don't pass small thumbnails as `src`. Use full-size sources, or a `srcset` that includes them
- Don't open a second overlay on top of it. Close one before opening another
Features
- Each group of controls has its own backing, so it stays readable over bright photos
- The counter shows `3 / 12` in monospace, and screen readers hear "3 of 12" followed by the alt text
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<div id="photos">
<a href="/photos/valley.jpg" data-caption="A river valley in evening light">
<img src="/photos/valley-thumb.jpg" alt="River valley" />
</a>
<a href="/photos/slope.jpg">
<img src="/photos/slope-thumb.jpg" alt="Mountain slope" />
</a>
</div>
<arc-lightbox gallery="#photos a" thumbnails>
<arc-icon-button slot="actions" name="download-simple" label="Download" variant="ghost"></arc-icon-button>
</arc-lightbox><img id="thumb" src="/photos/valley-thumb.jpg" alt="River valley" />
<arc-lightbox id="viewer"></arc-lightbox>
<script>
const viewer = document.querySelector('#viewer');
viewer.thumbnails = true;
viewer.images = [
{
src: '/photos/valley.jpg',
thumb: '/photos/valley-thumb.jpg',
alt: 'River valley',
caption: 'A river valley in evening light',
origin: '#thumb',
},
{ src: '/photos/slope.jpg', alt: 'Mountain slope' },
'/photos/canyon.jpg',
];
document.querySelector('#thumb').addEventListener('click', () => viewer.show(0));
</script>import { Lightbox } from '@arclux/arc-ui-react';
import { useState } from 'react';
const images = [
{ src: '/photos/valley.jpg', alt: 'River valley', caption: 'A river valley in evening light' },
{ src: '/photos/slope.jpg', alt: 'Mountain slope' },
'/photos/canyon.jpg',
];
function Gallery() {
const [open, setOpen] = useState(false);
return (
<>
<img src="/photos/valley-thumb.jpg" alt="River valley" onClick={() => setOpen(true)} />
<Lightbox images={images} open={open} onArcClose={() => setOpen(false)} />
</>
);
}<script setup>
import { ref } from 'vue';
import { Lightbox } from '@arclux/arc-ui-vue';
const open = ref(false);
const images = [
{ src: '/photos/valley.jpg', alt: 'River valley', caption: 'A river valley in evening light' },
{ src: '/photos/slope.jpg', alt: 'Mountain slope' },
'/photos/canyon.jpg',
];
</script>
<template>
<img src="/photos/valley-thumb.jpg" alt="River valley" @click="open = true" />
<Lightbox :images="images" :open="open" @arc-close="open = false" />
</template><script>
import { Lightbox } from '@arclux/arc-ui-svelte';
let open = $state(false);
const images = [
{ src: '/photos/valley.jpg', alt: 'River valley', caption: 'A river valley in evening light' },
{ src: '/photos/slope.jpg', alt: 'Mountain slope' },
'/photos/canyon.jpg',
];
</script>
<img src="/photos/valley-thumb.jpg" alt="River valley" onclick={() => open = true} />
<Lightbox {images} {open} on:arc-close={() => open = false} />import { Component } from '@angular/core';
import { Lightbox } from '@arclux/arc-ui-angular';
@Component({
imports: [Lightbox],
template: `
<img src="/photos/valley-thumb.jpg" alt="River valley" (click)="open = true" />
<arc-lightbox [images]="images" [open]="open" (arcClose)="open = false"></arc-lightbox>
`,
})
export class GalleryComponent {
open = false;
images = [
{ src: '/photos/valley.jpg', alt: 'River valley', caption: 'A river valley in evening light' },
{ src: '/photos/slope.jpg', alt: 'Mountain slope' },
'/photos/canyon.jpg',
];
}import { createSignal } from 'solid-js';
import { Lightbox } from '@arclux/arc-ui-solid';
const images = [
{ src: '/photos/valley.jpg', alt: 'River valley', caption: 'A river valley in evening light' },
{ src: '/photos/slope.jpg', alt: 'Mountain slope' },
'/photos/canyon.jpg',
];
function Gallery() {
const [open, setOpen] = createSignal(false);
return (
<>
<img src="/photos/valley-thumb.jpg" alt="River valley" onClick={() => setOpen(true)} />
<Lightbox images={images} open={open()} onArcClose={() => setOpen(false)} />
</>
);
}import { useState } from 'preact/hooks';
import { Lightbox } from '@arclux/arc-ui-preact';
const images = [
{ src: '/photos/valley.jpg', alt: 'River valley', caption: 'A river valley in evening light' },
{ src: '/photos/slope.jpg', alt: 'Mountain slope' },
'/photos/canyon.jpg',
];
function Gallery() {
const [open, setOpen] = useState(false);
return (
<>
<img src="/photos/valley-thumb.jpg" alt="River valley" onClick={() => setOpen(true)} />
<Lightbox images={images} open={open} onArcClose={() => setOpen(false)} />
</>
);
}API
gallerystringnull- CSS selector for links on the page to build the gallery from, such as
#photos a. Each match becomes an entry:hrefis the image, the inner<img>'saltis the alt text, anddata-caption(or the image'stitle) is the caption. A click on a match opens the viewer on it. Resolved against the lightbox's own document or shadow root, so links added later are included. Ignored whileimageshas entries. thumbnailsbooleanfalse- Shows a filmstrip of small thumbnails under the image. Each is a button that jumps to its image; the strip stays faint until pointed at or focused, and fades with the other controls when idle.
imagesArray[]- The gallery to display. Each entry is either a
srcstring or an object of shape{ src, alt, caption, srcset, sizes, width, height, thumb, origin }; everything butsrcis optional.widthandheightreserve the image's shape while it loads.thumbis a small source for the filmstrip (it falls back tosrc).originis the element the picture grows out of on open and back into on close, as an element or a selector; without it the viewer uses the element that was clicked or focused whenshow()ran, for the image it opened on. Set as a property, or as a JSON attribute for a gallery that is static. indexnumber0- Index of the image currently displayed. Navigation wraps at both ends, so setting it out of range shows the nearest valid image.
openbooleanfalse- Controls the visible state of the viewer. Set to
trueto open at the currentindexand activate the focus trap; set tofalseto close and restore focus to the previously-focused element.
Methods
show(index?)index?: number- Open the viewer, optionally jumping to a specific image first.
close()- Closes the viewer through the cancelable arc-close contract.
next()- Advances to the next image, wrapping past the end.
prev()- Steps to the previous image, wrapping past the start.
Events
arc-changedetail:{value: number, index: number}- Fired when the displayed image changes.
detail.valueis the new index. arc-close- Fired when the lightbox closes. Cancelable: call
preventDefault()to veto the close. arc-open- Fired when the lightbox opens
See also
- CarouselShows its children one at a time as full-width slides in a scroll-snapping strip.
- ImageImage with a shimmer skeleton while it loads, a fade-in, an error fallback and aspect ratio presets.
- DialogA modal overlay on the native dialog element, for forms, settings and other content that blocks the page.


