overlayshwc
z-lightboxLightbox
Media viewer overlay for images, videos, YouTube/Vimeo embeds, and iframes, collected from links, with zoom, swipe, captions, and dot/thumb navigation.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
target | string | 'a[href]' | Selector for trigger elements inside the host (default a[href]); each match becomes one lightbox item. |
active | number | 0 | Index of the item shown when opening; setting it while open navigates to that item. |
animation | 'slide' | 'fade' | 'scale' | 'slide' | Item transition: slide (default), fade, or scale. |
finite | boolean | false | Stops at the first/last item instead of wrapping. |
no-counter | boolean | false | Hides the current / total counter. |
nav | '' | 'dotnav' | 'thumbnav' | 'none' | 'false' | 'dotnav' | Navigation style: dotnav (default), thumbnav, or none/false/empty to hide it. |
no-slidenav | boolean | false | Hides the previous/next arrow buttons. |
no-zoom | boolean | false | Disables the zoom toggle for images. |
no-swipe | boolean | false | Disables swipe navigation between items. |
delay-controls | number | 3000 | Milliseconds of inactivity before the toolbar/chrome auto-hides (default 3000); pointer movement reveals it again. |
preload | number | 1 | Number of neighboring items to preload on each side of the active item (default 1). |
video-autoplay | boolean | false | Autoplays video items when shown. |
duration | number | 280 | Item transition duration in milliseconds (default 280). |
aria-label | string | 'Media viewer' | Accessible name of the viewer overlay (default Media viewer). |
Inherited from DialogMixin
| Attribute | Type | Default | Description |
|---|---|---|---|
open | boolean · reflects | false | Opens the dialog on first render and stays in sync with show() and hide(). |
center | boolean | false | Vertically centers the panel within the overlay. |
container | boolean | false | Adds z-modal-container to the overlay for a contained presentation. |
full | boolean | false | Adds z-modal-full to the overlay for a full-screen presentation. |
stack | boolean | false | Keeps other open dialogs open; without it, showing this dialog hides them. Stacked overlays receive increasing z-index. |
inline | boolean | false | Keeps the component in its original DOM position instead of teleporting it to document.body. |
no-bg-close | boolean | false | Disables closing when the overlay background is clicked. |
no-esc-close | boolean | false | Disables closing with the Esc key. |
unmount | boolean | false | Removes the rendered DOM after the close transition; the next show mounts it again. |
dialog-role | 'dialog' | 'alertdialog' | 'dialog' | ARIA role of the panel: dialog or alertdialog. |
aria-labelledby | string | '' | Id of the element that names the panel; takes precedence over aria-label. |
Inherited from Hwc
| Attribute | Type | Default | Description |
|---|---|---|---|
i18n | string | '' | Per-instance text overrides as key: text pairs, merged over the global z-i18n script and the built-in defaults. |
floating | string | '' | Floating UI placement options (for example offset and shiftPadding) parsed as key: value pairs. |
force-prevent-rerender | boolean | false | Skips re-rendering after the first render; an existing data-host-inner child is adopted as the rendered DOM. |
template | string | '' | Selector or id of an external element or <template> whose inner content is cloned in place of an inline template[data-fn="template"] child. |
Inherited from Base
| Attribute | Type | Default | Description |
|---|---|---|---|
cls | string | '' | Adds classes to named parts as key: classes pairs; a plain string targets the default part. |
stl | string | '' | Adds inline styles to named parts as key: styles pairs; a plain string targets the default part. |
Custom Styling (cls / stl)
Default cls target:overlay · defaultstl target:overlay
| Key | Default class | cls | stl | Description |
|---|---|---|---|---|
actions | z-lightbox-toolbar-actions | yes | yes | Toolbar action group (default z-lightbox-toolbar-actions). |
caption | z-lightbox-caption | yes | yes | Caption text under the active item (default z-lightbox-caption). |
close | z-slidenav z-lightbox-close | yes | yes | Close button (default z-slidenav z-lightbox-close). |
counter | z-lightbox-counter | yes | yes | The current / total counter (default z-lightbox-counter). |
dotnav | z-lightbox-dotnav z-dotnav | yes | yes | Dot navigation (default z-lightbox-dotnav z-dotnav). |
footer | z-lightbox-footer z-lightbox-chrome | yes | yes | Bottom chrome holding the caption (default z-lightbox-footer z-lightbox-chrome). |
items | z-lightbox-items | yes | yes | The deck holding the item slides (default z-lightbox-items). |
next | z-slidenav z-lightbox-slidenav z-position-center-right z-position-small z-lightbox-chrome | yes | yes | Next arrow (default z-slidenav z-lightbox-slidenav z-position-center-right z-position-small z-lightbox-chrome). |
overlay | z-lightbox | yes | yes | The lightbox overlay root (default z-lightbox); the default cls/stl target. |
prev | z-slidenav z-lightbox-slidenav z-position-center-left z-position-small z-lightbox-chrome | yes | yes | Previous arrow (default z-slidenav z-lightbox-slidenav z-position-center-left z-position-small z-lightbox-chrome). |
thumbnav | z-lightbox-thumbnav z-thumbnav | yes | yes | Thumbnail navigation (default z-lightbox-thumbnav z-thumbnav). |
toolbar | z-lightbox-toolbar z-lightbox-chrome | yes | yes | Top toolbar with counter and actions (default z-lightbox-toolbar z-lightbox-chrome). |
zoom | z-slidenav z-lightbox-zoom-btn | yes | yes | Zoom toggle button (default z-slidenav z-lightbox-zoom-btn). |
CSS Variables
| Variable | Default | Scope | Description |
|---|---|---|---|
--z-lightbox-bg | var(--z-bg) | .z-lightbox | Overlay base color, mixed with transparency using --z-lightbox-bg-o. |
--z-lightbox-bg-o | 95% | .z-lightbox | Overlay opacity percentage used in the background mix. |
--z-lightbox-blur | var(--z-global-blur) | .z-lightbox | Overlay backdrop blur radius. |
--z-lightbox-caption-bg | var(--z-bg) | .z-lightbox-caption | Caption background base color, mixed with transparency using --z-lightbox-caption-bg-o. |
--z-lightbox-caption-bg-o | 80% | .z-lightbox-caption | Caption background opacity percentage used in the mix. |
--z-lightbox-caption-color | var(--z-bg-f) | .z-lightbox-caption | Caption text base color, mixed with transparency using --z-lightbox-caption-color-o. |
--z-lightbox-caption-color-o | 100% | .z-lightbox-caption | Caption text opacity percentage used in the mix. |
--z-lightbox-caption-padding | 0.625rem 1rem | .z-lightbox-caption | Caption padding. |
--z-lightbox-iframe-height | 80% | .z-lightbox-iframe | Height of iframe/embed items. |
--z-lightbox-iframe-width | 80% | .z-lightbox-iframe | Width of iframe/embed items. |
--z-lightbox-thumb-max-height | 100px | .z-lightbox-thumbnav:not(.z-lightbox-thumbnav-vertical) :where(img, video) | Maximum thumbnail height in thumbnav. |
--z-lightbox-thumb-max-width | 100px | .z-lightbox-thumbnav-vertical :where(img, video) | Maximum thumbnail width in thumbnav. |
--z-lightbox-transition | opacity 150ms cubic-bezier(0.16, 1, 0.3, 1) | .z-lightbox | Transition timing of the viewer chrome. |
--z-lightbox-z-index | 1010 | .z-lightbox | Stacking order of the viewer. |
--z-lightbox-zoom-scale · hook | 1 | .z-lightbox-items > .z-lightbox-zoomed > img | Scale applied to a zoomed image. |
i18n Keys
| Key | Default | Placeholders | Description |
|---|---|---|---|
close | Close | — | Label of the close button. Used in: close. |
counter | {current} / {total} | current, total | Counter template with {current} and {total} placeholders. Used in: counter. |
error | Unable to load media. | — | Message shown when an item fails to load. |
next | Next | — | Label of the next arrow. Used in: next. |
previous | Previous | — | Label of the previous arrow. Used in: prev. |
slideLabel | Item {index} of {total} | index, total | Accessible slide label template with {index} and {total} placeholders. |
zoomIn | Zoom in | — | Label of the zoom toggle when zooming in. |
zoomOut | Zoom out | — | Label of the zoom toggle when zooming out. |
Events
| Event | Detail | Flags | Description |
|---|---|---|---|
z-lightbox:before-hide · from DialogMixin | — | cancelable, bubbles | Fires before closing; call preventDefault() to abort. |
z-lightbox:before-item-change | { index: number; previousIndex: number; item: LightboxItem; dir: 1 | -1 } | cancelable, bubbles | Cancelable; fires before navigating to another item. Detail: index, previousIndex, item, dir. |
z-lightbox:before-show · from DialogMixin | — | cancelable, bubbles | Fires before opening; call preventDefault() to abort. |
z-lightbox:destroy · from DialogMixin | — | bubbles | Fires when the mounted DOM is removed, via unmount or destroy(). |
z-lightbox:hidden · from DialogMixin | — | bubbles | Fires after the close transition completes and focus is restored to the opener. |
z-lightbox:hide · from DialogMixin | — | bubbles | Fires when the dialog starts closing. |
z-lightbox:item-change | Record<string, unknown> | bubbles | Fires when the active item changes, with the same detail as before-item-change. |
z-lightbox:item-error | { index: number; item: LightboxItem } | bubbles | Fires when an item's media fails to load. Detail: index, item. |
z-lightbox:item-load | { index: number; item: LightboxItem } | bubbles | Fires when an item's media finishes loading. Detail: index, item. |
z-lightbox:item-shown | Record<string, unknown> | bubbles | Fires after the item transition completes, with the same detail as before-item-change. |
z-lightbox:mount · from DialogMixin | — | bubbles | Fires once when the dialog DOM is first mounted. |
z-lightbox:show · from DialogMixin | — | bubbles | Fires when the dialog starts opening, before the transition completes. |
z-lightbox:shown · from DialogMixin | — | bubbles | Fires after the open transition completes. |
Methods
| Signature | Description |
|---|---|
destroy(removeHost?: boolean = false): Promise<void> | Closes and unmounts the dialog DOM; optionally removes the host element as well. |
goTo(target: number | 'next' | 'previous' | 'first' | 'last', animate?: boolean = true): Promise<boolean> | Navigates to an index (wraps unless finite); resolves to whether the item changed. |
hide(): Promise<void> | Closes the dialog and restores focus to the opener. |
index(): number | Returns the current item index. |
next(animate?: boolean = true): Promise<boolean> | Advances to the next item. |
previous(animate?: boolean = true): Promise<boolean> | Moves to the previous item. |
refresh(): void | Re-collects items from the trigger elements. |
show(target?: number | HTMLElement | null): Promise<void> | Opens the dialog; the trigger element receives focus back on close. |
toggle(trigger?: HTMLElement | null): Promise<void> | Opens the dialog if closed, otherwise closes it. |
toggleZoom(): void | Toggles zoom on the active image item. |
Data Hooks
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-alt | — | descendant | config | On a trigger: alt text for the image item. |
data-caption | — | descendant | config | On a trigger: caption shown under the item. |
data-close · from DialogMixin | — | external-trigger | trigger | Clicking the element closes the dialog matched by the selector (usually #id). |
data-host-inner · from Hwc | — | descendant | config | Marks the rendered inner wrapper so force-prevent-rerender can adopt server-rendered DOM without re-rendering. |
data-lightbox-ignore | — | descendant | config | Excludes a trigger (or subtree) from item collection. |
data-lightbox-slide | — | descendant | marker | Set by the component on each slide to its index. |
data-open · from DialogMixin | — | external-trigger | trigger | Clicking the element opens the dialog matched by the selector without toggling. |
data-part | items, overlay | descendant | marker | Marks the overlay and items deck in the rendered DOM (data-part="overlay" / data-part="items"). |
data-poster | — | descendant | config | On a trigger: poster image for a video item. |
data-reactive · from Hwc | — | descendant | config | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
data-sizes | — | descendant | config | On a trigger: sizes attribute for the responsive image. |
data-source | #, #! | descendant | trigger | On a trigger: explicit media URL when the href is a placeholder (#/#!) or differs from the media. |
data-srcset | — | descendant | config | On a trigger: srcset attribute for the responsive image. |
data-thumb | — | descendant | config | On a trigger: thumbnail URL for thumbnav. |
data-toggle · from DialogMixin | — | external-trigger | trigger | Clicking the element toggles the dialog matched by the selector (usually #id). |
data-type | iframe, image, video, vimeo, youtube | descendant | trigger | On a trigger: media type override — image, video, youtube, vimeo, or iframe; otherwise inferred from the URL. |
Child Content
script[data-fn="config"][type="application/json"]
JSON configuration script parsed by the base class (i18n, cls, stl, floating).
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | config | Marks the script as configuration (value: config). |
data-reactive | no | boolean | Re-parses the configuration when the script mutates. |
select[data-fn="data-source"]
Hidden select parsed into grouped option data by the base class.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | data-source | Marks the select as the data source (value: data-source). |
data-reactive | no | boolean | Re-parses the options when the select mutates. |
optgroup · repeatable
Groups options under a label.
| Attribute | Required | Type | Description |
|---|---|---|---|
label | yes | string | Group header text; also the default group key. |
disabled | no | boolean | Disables every option in the group. |
data-key | no | string | Overrides the group key used in the parsed data. |
data-keywords | no | comma-separated string | Comma-separated keywords stored with the group's data. |
option · repeatable
One option entry within the group.
| Attribute | Required | Type | Description |
|---|---|---|---|
value | no | string | Value carried by this option in the parsed data. |
disabled | no | boolean | Makes the option non-selectable. |
selected | no | boolean | Marks the option as initially selected. |
data-keywords | no | comma-separated string | Extra search terms, comma-separated; searched alongside the label and value. |
option · repeatable
One ungrouped option entry.
| Attribute | Required | Type | Description |
|---|---|---|---|
value | no | string | Value carried by this option in the parsed data. |
disabled | no | boolean | Makes the option non-selectable. |
selected | no | boolean | Marks the option as initially selected. |
data-keywords | no | comma-separated string | Extra search terms, comma-separated. |
template[data-fn="icons"]
Instance-level icon repository.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | icons | Marks the template as an icon source (value: icons). |
data-reactive | no | boolean | Re-parses the icons when the template mutates. |
* · repeatable
One icon element.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-key | yes | string | Icon key referenced by $icons. |
template[data-fn="template"]
Deferred content template mounted by the base class.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | template | Marks the template for deferred mounting (value: template). |
data-reactive | no | boolean | Re-parses the template when it mutates. |
CSS Classes
| Class | Role | Applies to | Description |
|---|---|---|---|
.z-lightbox | root | z-lightbox | Overlay root: fixed, dimmed, blurred viewer. |
.z-lightbox-caption | state | .z-lightbox | Caption text styling. |
.z-lightbox-chrome | element | .z-lightbox | Shared chrome class faded out when controls auto-hide. |
.z-lightbox-controls-hidden | element | .z-lightbox | State class while the chrome is hidden. |
.z-lightbox-counter | state | .z-lightbox | The item counter. |
.z-lightbox-dotnav | element | .z-lightbox | Dot navigation list. |
.z-lightbox-footer | element | .z-lightbox | Bottom chrome holding the caption. |
.z-lightbox-iframe | element | .z-lightbox | Sizing frame for iframe/embed items. |
.z-lightbox-items | state | .z-lightbox | The deck holding the item slides. |
.z-lightbox-items-fit | modifier | .z-lightbox | Fit mode sizing the deck to the media. |
.z-lightbox-loader | element | .z-lightbox | Loading indicator shown while media loads. |
.z-lightbox-page | element | .z-lightbox | Page root class clipping scroll while the viewer is open. |
.z-lightbox-slidenav | element | .z-lightbox | Previous/next arrow buttons. |
.z-lightbox-thumbnav | element | .z-lightbox | Thumbnail navigation list. |
.z-lightbox-thumbnav-vertical | element | .z-lightbox | Vertical thumbnail navigation. |
.z-lightbox-toolbar | element | .z-lightbox | Top toolbar chrome. |
.z-lightbox-toolbar-actions | state | .z-lightbox | Toolbar action group. |
.z-lightbox-zoom | modifier | .z-lightbox | Zoom affordance styling. |
.z-lightbox-zoomed | element | .z-lightbox | State class while an image is zoomed. |
Keyboard
| Keys | Action | When |
|---|---|---|
| ArrowLeft ArrowRight | Previous/next item (direction flips in RTL). | — |
| Escape | Closes the viewer (or exits zoom first). | — |
Accessibility
| Part | ARIA | Description |
|---|---|---|
actions | — | Toolbar action group; no static ARIA attributes. |
caption | — | Caption text; no static ARIA attributes. |
close | aria-label="${closeLabel}" | Close button labeled by the close i18n text. |
counter | aria-live="polite" | Item counter with aria-live="polite". |
dotnav | role="tablist" | Dot navigation with role="tablist". |
footer | — | Bottom chrome; no static ARIA attributes. |
items | — | Slide deck; no static ARIA attributes (slides are labeled individually). |
next | aria-disabled="${atLast ? 'true' : 'false'}" aria-label="${nextLabel}" | Next arrow labeled by the next i18n text; aria-disabled at the last item when finite. |
overlay | aria-label="${this.ariaLabelText || 'Media viewer'}" aria-modal="true" role="dialog" | Viewer overlay: role="dialog", aria-modal="true", labeled by aria-label (default Media viewer). |
prev | aria-disabled="${atFirst ? 'true' : 'false'}" aria-label="${prevLabel}" | Previous arrow labeled by the previous i18n text; aria-disabled at the first item when finite. |
thumbnav | role="tablist" | Thumbnail navigation with role="tablist". |
toolbar | — | Top toolbar; no static ARIA attributes. |
zoom | aria-label="${zoomLabel}" aria-pressed="${this.isZoomed ? 'true' : 'false'}" | Zoom toggle labeled by the zoomIn/zoomOut i18n text; aria-pressed reflects the zoom state. |
- Triggers are kept button-accessible and linked to the viewer; slides are labeled with the
slideLabeltemplate. - The viewer renders into a portal appended to
document.body; the host stays in place as the trigger container.