overlayshwcz-lightbox

Lightbox

Media viewer overlay for images, videos, YouTube/Vimeo embeds, and iframes, collected from links, with zoom, swipe, captions, and dot/thumb navigation.

Attributes

AttributeTypeDefaultDescription
targetstring'a[href]'Selector for trigger elements inside the host (default a[href]); each match becomes one lightbox item.
activenumber0Index 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.
finitebooleanfalseStops at the first/last item instead of wrapping.
no-counterbooleanfalseHides the current / total counter.
nav'' | 'dotnav' | 'thumbnav' | 'none' | 'false''dotnav'Navigation style: dotnav (default), thumbnav, or none/false/empty to hide it.
no-slidenavbooleanfalseHides the previous/next arrow buttons.
no-zoombooleanfalseDisables the zoom toggle for images.
no-swipebooleanfalseDisables swipe navigation between items.
delay-controlsnumber3000Milliseconds of inactivity before the toolbar/chrome auto-hides (default 3000); pointer movement reveals it again.
preloadnumber1Number of neighboring items to preload on each side of the active item (default 1).
video-autoplaybooleanfalseAutoplays video items when shown.
durationnumber280Item transition duration in milliseconds (default 280).
aria-labelstring'Media viewer'Accessible name of the viewer overlay (default Media viewer).
Inherited from DialogMixin
AttributeTypeDefaultDescription
openboolean · reflectsfalseOpens the dialog on first render and stays in sync with show() and hide().
centerbooleanfalseVertically centers the panel within the overlay.
containerbooleanfalseAdds z-modal-container to the overlay for a contained presentation.
fullbooleanfalseAdds z-modal-full to the overlay for a full-screen presentation.
stackbooleanfalseKeeps other open dialogs open; without it, showing this dialog hides them. Stacked overlays receive increasing z-index.
inlinebooleanfalseKeeps the component in its original DOM position instead of teleporting it to document.body.
no-bg-closebooleanfalseDisables closing when the overlay background is clicked.
no-esc-closebooleanfalseDisables closing with the Esc key.
unmountbooleanfalseRemoves 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-labelledbystring''Id of the element that names the panel; takes precedence over aria-label.
Inherited from Hwc
AttributeTypeDefaultDescription
i18nstring''Per-instance text overrides as key: text pairs, merged over the global z-i18n script and the built-in defaults.
floatingstring''Floating UI placement options (for example offset and shiftPadding) parsed as key: value pairs.
force-prevent-rerenderbooleanfalseSkips re-rendering after the first render; an existing data-host-inner child is adopted as the rendered DOM.
templatestring''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
AttributeTypeDefaultDescription
clsstring''Adds classes to named parts as key: classes pairs; a plain string targets the default part.
stlstring''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

KeyDefault classclsstlDescription
actionsz-lightbox-toolbar-actionsyesyesToolbar action group (default z-lightbox-toolbar-actions).
captionz-lightbox-captionyesyesCaption text under the active item (default z-lightbox-caption).
closez-slidenav z-lightbox-closeyesyesClose button (default z-slidenav z-lightbox-close).
counterz-lightbox-counteryesyesThe current / total counter (default z-lightbox-counter).
dotnavz-lightbox-dotnav z-dotnavyesyesDot navigation (default z-lightbox-dotnav z-dotnav).
footerz-lightbox-footer z-lightbox-chromeyesyesBottom chrome holding the caption (default z-lightbox-footer z-lightbox-chrome).
itemsz-lightbox-itemsyesyesThe deck holding the item slides (default z-lightbox-items).
nextz-slidenav z-lightbox-slidenav z-position-center-right z-position-small z-lightbox-chromeyesyesNext arrow (default z-slidenav z-lightbox-slidenav z-position-center-right z-position-small z-lightbox-chrome).
overlayz-lightboxyesyesThe lightbox overlay root (default z-lightbox); the default cls/stl target.
prevz-slidenav z-lightbox-slidenav z-position-center-left z-position-small z-lightbox-chromeyesyesPrevious arrow (default z-slidenav z-lightbox-slidenav z-position-center-left z-position-small z-lightbox-chrome).
thumbnavz-lightbox-thumbnav z-thumbnavyesyesThumbnail navigation (default z-lightbox-thumbnav z-thumbnav).
toolbarz-lightbox-toolbar z-lightbox-chromeyesyesTop toolbar with counter and actions (default z-lightbox-toolbar z-lightbox-chrome).
zoomz-slidenav z-lightbox-zoom-btnyesyesZoom toggle button (default z-slidenav z-lightbox-zoom-btn).

CSS Variables

VariableDefaultScopeDescription
--z-lightbox-bgvar(--z-bg).z-lightboxOverlay base color, mixed with transparency using --z-lightbox-bg-o.
--z-lightbox-bg-o95%.z-lightboxOverlay opacity percentage used in the background mix.
--z-lightbox-blurvar(--z-global-blur).z-lightboxOverlay backdrop blur radius.
--z-lightbox-caption-bgvar(--z-bg).z-lightbox-captionCaption background base color, mixed with transparency using --z-lightbox-caption-bg-o.
--z-lightbox-caption-bg-o80%.z-lightbox-captionCaption background opacity percentage used in the mix.
--z-lightbox-caption-colorvar(--z-bg-f).z-lightbox-captionCaption text base color, mixed with transparency using --z-lightbox-caption-color-o.
--z-lightbox-caption-color-o100%.z-lightbox-captionCaption text opacity percentage used in the mix.
--z-lightbox-caption-padding0.625rem 1rem.z-lightbox-captionCaption padding.
--z-lightbox-iframe-height80%.z-lightbox-iframeHeight of iframe/embed items.
--z-lightbox-iframe-width80%.z-lightbox-iframeWidth of iframe/embed items.
--z-lightbox-thumb-max-height100px.z-lightbox-thumbnav:not(.z-lightbox-thumbnav-vertical) :where(img, video)Maximum thumbnail height in thumbnav.
--z-lightbox-thumb-max-width100px.z-lightbox-thumbnav-vertical :where(img, video)Maximum thumbnail width in thumbnav.
--z-lightbox-transitionopacity 150ms cubic-bezier(0.16, 1, 0.3, 1).z-lightboxTransition timing of the viewer chrome.
--z-lightbox-z-index1010.z-lightboxStacking order of the viewer.
--z-lightbox-zoom-scale · hook1.z-lightbox-items > .z-lightbox-zoomed > imgScale applied to a zoomed image.

i18n Keys

KeyDefaultPlaceholdersDescription
closeClose—Label of the close button. Used in: close.
counter{current} / {total}current, totalCounter template with {current} and {total} placeholders. Used in: counter.
errorUnable to load media.—Message shown when an item fails to load.
nextNext—Label of the next arrow. Used in: next.
previousPrevious—Label of the previous arrow. Used in: prev.
slideLabelItem {index} of {total}index, totalAccessible slide label template with {index} and {total} placeholders.
zoomInZoom in—Label of the zoom toggle when zooming in.
zoomOutZoom out—Label of the zoom toggle when zooming out.

Events

EventDetailFlagsDescription
z-lightbox:before-hide · from DialogMixin—cancelable, bubblesFires before closing; call preventDefault() to abort.
z-lightbox:before-item-change{ index: number; previousIndex: number; item: LightboxItem; dir: 1 | -1 }cancelable, bubblesCancelable; fires before navigating to another item. Detail: index, previousIndex, item, dir.
z-lightbox:before-show · from DialogMixin—cancelable, bubblesFires before opening; call preventDefault() to abort.
z-lightbox:destroy · from DialogMixin—bubblesFires when the mounted DOM is removed, via unmount or destroy().
z-lightbox:hidden · from DialogMixin—bubblesFires after the close transition completes and focus is restored to the opener.
z-lightbox:hide · from DialogMixin—bubblesFires when the dialog starts closing.
z-lightbox:item-changeRecord<string, unknown>bubblesFires when the active item changes, with the same detail as before-item-change.
z-lightbox:item-error{ index: number; item: LightboxItem }bubblesFires when an item's media fails to load. Detail: index, item.
z-lightbox:item-load{ index: number; item: LightboxItem }bubblesFires when an item's media finishes loading. Detail: index, item.
z-lightbox:item-shownRecord<string, unknown>bubblesFires after the item transition completes, with the same detail as before-item-change.
z-lightbox:mount · from DialogMixin—bubblesFires once when the dialog DOM is first mounted.
z-lightbox:show · from DialogMixin—bubblesFires when the dialog starts opening, before the transition completes.
z-lightbox:shown · from DialogMixin—bubblesFires after the open transition completes.

Methods

SignatureDescription
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(): numberReturns 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(): voidRe-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(): voidToggles zoom on the active image item.

Data Hooks

AttributeValuesApplies toRoleDescription
data-alt—descendantconfigOn a trigger: alt text for the image item.
data-caption—descendantconfigOn a trigger: caption shown under the item.
data-close · from DialogMixin—external-triggertriggerClicking the element closes the dialog matched by the selector (usually #id).
data-host-inner · from Hwc—descendantconfigMarks the rendered inner wrapper so force-prevent-rerender can adopt server-rendered DOM without re-rendering.
data-lightbox-ignore—descendantconfigExcludes a trigger (or subtree) from item collection.
data-lightbox-slide—descendantmarkerSet by the component on each slide to its index.
data-open · from DialogMixin—external-triggertriggerClicking the element opens the dialog matched by the selector without toggling.
data-partitems, overlaydescendantmarkerMarks the overlay and items deck in the rendered DOM (data-part="overlay" / data-part="items").
data-poster—descendantconfigOn a trigger: poster image for a video item.
data-reactive · from Hwc—descendantconfigOpts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates.
data-sizes—descendantconfigOn a trigger: sizes attribute for the responsive image.
data-source#, #!descendanttriggerOn a trigger: explicit media URL when the href is a placeholder (#/#!) or differs from the media.
data-srcset—descendantconfigOn a trigger: srcset attribute for the responsive image.
data-thumb—descendantconfigOn a trigger: thumbnail URL for thumbnav.
data-toggle · from DialogMixin—external-triggertriggerClicking the element toggles the dialog matched by the selector (usually #id).
data-typeiframe, image, video, vimeo, youtubedescendanttriggerOn 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).

AttributeRequiredTypeDescription
data-fnyesconfigMarks the script as configuration (value: config).
data-reactivenobooleanRe-parses the configuration when the script mutates.

select[data-fn="data-source"]

Hidden select parsed into grouped option data by the base class.

AttributeRequiredTypeDescription
data-fnyesdata-sourceMarks the select as the data source (value: data-source).
data-reactivenobooleanRe-parses the options when the select mutates.

optgroup · repeatable

Groups options under a label.

AttributeRequiredTypeDescription
labelyesstringGroup header text; also the default group key.
disablednobooleanDisables every option in the group.
data-keynostringOverrides the group key used in the parsed data.
data-keywordsnocomma-separated stringComma-separated keywords stored with the group's data.

option · repeatable

One option entry within the group.

AttributeRequiredTypeDescription
valuenostringValue carried by this option in the parsed data.
disablednobooleanMakes the option non-selectable.
selectednobooleanMarks the option as initially selected.
data-keywordsnocomma-separated stringExtra search terms, comma-separated; searched alongside the label and value.

option · repeatable

One ungrouped option entry.

AttributeRequiredTypeDescription
valuenostringValue carried by this option in the parsed data.
disablednobooleanMakes the option non-selectable.
selectednobooleanMarks the option as initially selected.
data-keywordsnocomma-separated stringExtra search terms, comma-separated.

template[data-fn="icons"]

Instance-level icon repository.

AttributeRequiredTypeDescription
data-fnyesiconsMarks the template as an icon source (value: icons).
data-reactivenobooleanRe-parses the icons when the template mutates.

* · repeatable

One icon element.

AttributeRequiredTypeDescription
data-keyyesstringIcon key referenced by $icons.

template[data-fn="template"]

Deferred content template mounted by the base class.

AttributeRequiredTypeDescription
data-fnyestemplateMarks the template for deferred mounting (value: template).
data-reactivenobooleanRe-parses the template when it mutates.

CSS Classes

ClassRoleApplies toDescription
.z-lightboxrootz-lightboxOverlay root: fixed, dimmed, blurred viewer.
.z-lightbox-captionstate.z-lightboxCaption text styling.
.z-lightbox-chromeelement.z-lightboxShared chrome class faded out when controls auto-hide.
.z-lightbox-controls-hiddenelement.z-lightboxState class while the chrome is hidden.
.z-lightbox-counterstate.z-lightboxThe item counter.
.z-lightbox-dotnavelement.z-lightboxDot navigation list.
.z-lightbox-footerelement.z-lightboxBottom chrome holding the caption.
.z-lightbox-iframeelement.z-lightboxSizing frame for iframe/embed items.
.z-lightbox-itemsstate.z-lightboxThe deck holding the item slides.
.z-lightbox-items-fitmodifier.z-lightboxFit mode sizing the deck to the media.
.z-lightbox-loaderelement.z-lightboxLoading indicator shown while media loads.
.z-lightbox-pageelement.z-lightboxPage root class clipping scroll while the viewer is open.
.z-lightbox-slidenavelement.z-lightboxPrevious/next arrow buttons.
.z-lightbox-thumbnavelement.z-lightboxThumbnail navigation list.
.z-lightbox-thumbnav-verticalelement.z-lightboxVertical thumbnail navigation.
.z-lightbox-toolbarelement.z-lightboxTop toolbar chrome.
.z-lightbox-toolbar-actionsstate.z-lightboxToolbar action group.
.z-lightbox-zoommodifier.z-lightboxZoom affordance styling.
.z-lightbox-zoomedelement.z-lightboxState class while an image is zoomed.

Keyboard

KeysActionWhen
ArrowLeft ArrowRightPrevious/next item (direction flips in RTL).—
EscapeCloses the viewer (or exits zoom first).—

Accessibility

PartARIADescription
actions—Toolbar action group; no static ARIA attributes.
caption—Caption text; no static ARIA attributes.
closearia-label="${closeLabel}"Close button labeled by the close i18n text.
counteraria-live="polite"Item counter with aria-live="polite".
dotnavrole="tablist"Dot navigation with role="tablist".
footer—Bottom chrome; no static ARIA attributes.
items—Slide deck; no static ARIA attributes (slides are labeled individually).
nextaria-disabled="${atLast ? 'true' : 'false'}" aria-label="${nextLabel}"Next arrow labeled by the next i18n text; aria-disabled at the last item when finite.
overlayaria-label="${this.ariaLabelText || 'Media viewer'}" aria-modal="true" role="dialog"Viewer overlay: role="dialog", aria-modal="true", labeled by aria-label (default Media viewer).
prevaria-disabled="${atFirst ? 'true' : 'false'}" aria-label="${prevLabel}"Previous arrow labeled by the previous i18n text; aria-disabled at the first item when finite.
thumbnavrole="tablist"Thumbnail navigation with role="tablist".
toolbar—Top toolbar; no static ARIA attributes.
zoomaria-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 slideLabel template.
  • The viewer renders into a portal appended to document.body; the host stays in place as the trigger container.