Open the viewer at index (default: the current one). Focus returns to opener on close
(default: that image's thumbnail).
close()
Close the viewer.
next()
Show the next image (wraps).
previous()
Show the previous image (wraps).
Events
Event
Description
close
Fired after the viewer closes.
Slots
Slot
Description
(default)
The thumbnails: links to the full images (<a href><img alt></a>, optionally in a figure with a figcaption).
CSS parts
Style the inside of the component with ::part(), for example focsd-lightbox::part(thumbs).
Part
Description
thumbs
The wrapper of the thumbnails.
dialog
The viewer dialog.
figure
The figure that holds the image and its caption.
image
The full image.
caption
The caption (the `figcaption`, else the alt).
counter
"Image 3 of 8".
controls
The row of buttons.
button
Each button.
prev
The previous image button.
next
The next image button.
close
The close button.
Accessibility
The thumbnails are ordinary links to the full-size pictures, so without JavaScript each one opens its picture. A click with a modifier key, or a middle click, keeps its normal meaning.
The viewer is a native modal dialog named by label (default "Image viewer"): the page behind is inert and Escape closes it. Focus returns to the thumbnail that opened it.
Focus starts on Next (or on Close when there is one picture), so the arrow keys and Enter work at once.
Each change is announced politely, for example "Image 2 of 4, Hills near the coast". The counter and the caption describe the dialog.
Every picture needs alt text: the viewer shows it, and a missing one is warned about. Captions come from a figcaption.
Previous and Next wrap at the ends, so the counter tells you where you are. The slide fades in by opacity only, and not at all under reduced motion.
Swipe horizontally on a touch screen (at least 40 px) to move between pictures. The buttons are 44 px targets and the chevrons mirror in right-to-left text.
Keyboard
Key
Action
Enter
Open the viewer from a thumbnail
Arrow Left / Right
Previous / next picture (swapped in right-to-left text)
Home / End
First / last picture
Escape
Close and return to the thumbnail
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.