Which one to useLink to the section Which one to use
- A plain page or an Astro site. Do nothing: the site kit script enhances every content image in
mainby itself. - A React app. Use
Lightboxand keep the open state and the index yourself.
In a site: nothing to writeLink to the section In a site: nothing to write
PageLayout includes the script. It turns an image in main into a button that opens the dialog, with the alt text in its name.
- Figures that share one parent open as a group.
data-sk-lightbox-groupon any element groups the images inside it.data-sk-fullon an image names a larger file than the one shown.
The script leaves these alone, and so does the attribute below:
- images inside a link or a button, since they already do something;
- decorative images with an empty alt, and the header, footer and navigation;
- anything inside, or marked with,
data-sk-lightbox="off".
The first image opens in the lightbox; the second one does not.
<figure>
<img src="/shots/editor.webp" alt="The editor with a draft open" />
<figcaption>The editor</figcaption>
</figure>
<img src="/logo-wall.webp" alt="Logos" data-sk-lightbox="off" />In ReactLink to the section In React
<Lightbox images={images} index={index} onIndexChange={setIndex} isOpen={open} onOpenChange={setOpen} labels={labels} />Every word is a label, including the position and the names of the thumbnails, so the app keeps its own language files.
ControlsLink to the section Controls
| Action | How | Note |
|---|---|---|
| Close | Close button, Escape, a click on the backdrop | Focus returns to the image that was opened |
| Zoom | Plus and minus buttons, + and - keys, the wheel, a pinch, a double click or double tap | Zero or the reset button returns to the whole picture |
| Pan | Drag, or the arrow keys, while zoomed in | The picture cannot leave the screen |
| Previous and next | Arrow buttons, the left and right arrow keys, a swipe on a phone | Home and End go to the first and last picture |
| Jump | The thumbnail row at the bottom | The current thumbnail is marked with aria-current |
Writing the alt textLink to the section Writing the alt text
The picture is what the reader sees
alt="The editor with a draft open and the outline on the left"alt="screenshot"AccessibilityLink to the section Accessibility
- A modal dialog with a name; focus starts on Close, stays inside and returns to the image.
- Every control is a button with a name, and the zoom and arrows work from the keyboard.
- The position is announced politely when it changes.
- The dialog uses the theme tokens, so it is right in the three themes and in forced colours.
- With reduced motion, the fade and the zoom animation drop out.
Built to WCAG 2.2 AA as a target.