Accessibility
Dialog semantics, focus management, live announcements and reduced motion, the same contract in every package.
lightGallery v3 ships one accessibility contract across the vanilla library and the React, Vue and Angular packages, the suites for all four run axe checks against WCAG 2.0/2.1 A and AA rules.
Dialog semantics
The open gallery is a modal dialog:
role="dialog"witharia-modal="true".- Accessible name: point
ariaLabelledbyat your own caption element, or let the built-in label apply,strings.galleryLabel(default'Gallery', localizable). ariaDescribedbyis available for a longer description.- Every control is a real
<button>with a localizablearia-labelfrom the samestringsobject.
Focus management
With trapFocus (default true):
- Focus moves into the gallery when it opens and cycles inside it,
Tabnever escapes to the page behind the backdrop. - When the gallery closes, focus returns to the trigger that opened it.
Screen-reader announcements
With ariaAnnouncements (default true), the gallery maintains a
dedicated polite live region (.lg-announcer) and announces every
slide change:
- The template is
strings.slideAnnouncement, default'Image {index} of {total}', with{index}and{total}replaced by the 1-based position and slide count. - The slide’s caption, when present, is appended to the announcement.
- While announcements are active, the visual counter is
aria-hiddenand the caption bar is not a live region, each slide change is announced exactly once. - Set
ariaAnnouncements: falseto restore the previous behavior (live-region counter and caption bar, no announcer).
lightGallery(el, {
ariaAnnouncements: true,
strings: {
galleryLabel: 'Product photos',
slideAnnouncement: 'Photo {index} of {total}',
},
});
Keyboard
Escapecloses the gallery (escKey, defaulttrue).ArrowLeft/ArrowRightnavigate, and follow the reading direction under RTL.- Controls are focusable buttons and activate with
Enter/Space.
Reduced motion
When the OS reports prefers-reduced-motion: reduce, every package
automatically collapses the gallery’s motion: slide and open/close
animation durations drop to 0, the backdrop appears instantly, and
the zoom-from-origin and slide-end animations are disabled. No
configuration needed, the preference wins over configured
animation settings.
Settings
Every setting below has its generated description in the settings reference.
| Setting | Default | Description |
|---|---|---|
trapFocus | true | Trap focus inside the open gallery; restore it to the trigger on close |
ariaAnnouncements | true | Announce slide changes through a dedicated polite live region |
ariaLabelledby | '' | ID of the element that labels the gallery dialog |
ariaDescribedby | '' | ID of the element that describes the gallery dialog |
escKey | true | Close the gallery with Escape |
strings.galleryLabel | 'Gallery' | Dialog label when ariaLabelledby is not set |
strings.slideAnnouncement | 'Image {index} of {total}' | Announcement template for slide changes |
lightGallery