Getting startedComponentsDesign tokensThemingTheme synthesizerFrameworksAccessibilityUtilitiesServer renderingBrowser supportContributingChangelogApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip
ARC UIARC Radiant Components
v4.9DocsComponentsTokensSynthesizer
Getting startedFrameworksServer renderingDesign tokensThemingTheme synthesizerTypographyUtilitiesAll componentsAccessibilityBrowser supportChangelogContributingStatsApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip

Lightbox

A full-screen viewer for a gallery of images, opened from a thumbnail and zoomable up to 4x.

ComponentsLightbox
contentinteractive
<arc-lightbox>

Overview

Lightbox shows a gallery of images at full screen, above the page behind a blurred backdrop. It shares the overlay infrastructure with Dialog and Sheet: focus is trapped while open, page scroll is locked, Escape and a backdrop click dismiss, and focus returns to the trigger on close. Open it from a thumbnail with `show(index)`, or set `open` and `index` directly. There are two ways to give it pictures. Set the `images` property to an array of `src` strings or `{ src, alt, caption, srcset, sizes, width, height }` objects, and one array can mix the two. Or set `gallery` to a selector for links already on the page, such as `gallery="#photos a"`. Each matched `<a href>` becomes an entry, with alt text from the image inside it and a caption from `data-caption`. A click on one opens the viewer on that picture. The links are read at click time, so ones added later are included, and without JavaScript they still open the full-size image. Stepping wraps at both ends. Move with the arrow buttons, the arrow keys, Home and End, or a sideways swipe on touch. Each step fires `arc-change` with the new index in `detail.value`, and the images either side of the current one are fetched ahead so a step shows at once. A slow image gets a spinner after 150ms, and one that fails shows a short message and its alt text instead of a broken picture. Zoom runs from 1x to 4x. Pinch or Ctrl + wheel zooms toward the fingers or the pointer, a double-click or double-tap zooms to 2x at that spot, and `+`, `-` and `0` step and reset it. While zoomed, dragging and the arrow keys pan, and the image's edges never come inside the frame. Stepping to another image or closing resets the zoom. Opened from a thumbnail, the picture grows out of it, and on close it shrinks back into the thumbnail of whichever image is showing. Each step slides the picture a short way in the direction of travel. Under reduced motion both become a plain fade. A gallery link is the thumbnail for its own image. With the `images` property, the first image grows from whatever was clicked or focused when `show()` ran, and an entry's `origin` (an element or a selector) sets the thumbnail for any image. Add `thumbnails` for a filmstrip under the picture. It stays faint until you point at it or tab into it, marks the current image with a short glowing bar, and jumps on click. An entry's `thumb` gives it a small source; otherwise the strip uses `src`, loaded lazily. The top bar and the arrows fade after a few seconds without movement, and come back on any pointer movement, key press or tap. They stay while a keyboard user has focus in them. The `actions` slot adds your own buttons to the bar, for download or share. `next()`, `prev()` and `close()` drive the viewer from outside, with the same events as the built-in controls. `arc-close` is cancelable on every path, including a swipe down and a programmatic `close()`, so a veto always holds.

Guidelines

Do

  • Use it for photo galleries, screenshots and other images worth seeing at full size
  • Prefer `gallery` when the thumbnails already link to the full images
  • Open it from a visible thumbnail so the viewer starts on the image the reader chose
  • Give every entry `alt` text. It also labels the dialog and is read out on each step
  • Add `thumbnails` for galleries longer than a handful of images, where stepping one at a time is slow
  • Pass `width` and `height` when you know them, so the frame holds its shape while the image loads
  • Use `caption` for attribution or context that should travel with the image

Don't

  • Don't use it for anything but images. Use Dialog
  • Don't open it on page load. Let the reader choose a full-screen view
  • Don't pass small thumbnails as `src`. Use full-size sources, or a `srcset` that includes them
  • Don't open a second overlay on top of it. Close one before opening another

Features

  • Each group of controls has its own backing, so it stays readable over bright photos
  • The counter shows `3 / 12` in monospace, and screen readers hear "3 of 12" followed by the alt text

Preview

River between mountains Mountain slope Canyon river

Usage

This component needs JavaScript. Use the Web Component or a framework wrapper.

<div id="photos">
  <a href="/photos/valley.jpg" data-caption="A river valley in evening light">
    <img src="/photos/valley-thumb.jpg" alt="River valley" />
  </a>
  <a href="/photos/slope.jpg">
    <img src="/photos/slope-thumb.jpg" alt="Mountain slope" />
  </a>
</div>

<arc-lightbox gallery="#photos a" thumbnails>
  <arc-icon-button slot="actions" name="download-simple" label="Download" variant="ghost"></arc-icon-button>
</arc-lightbox>

API

gallerystringnull
CSS selector for links on the page to build the gallery from, such as #photos a. Each match becomes an entry: href is the image, the inner <img>'s alt is the alt text, and data-caption (or the image's title) is the caption. A click on a match opens the viewer on it. Resolved against the lightbox's own document or shadow root, so links added later are included. Ignored while images has entries.
thumbnailsbooleanfalse
Shows a filmstrip of small thumbnails under the image. Each is a button that jumps to its image; the strip stays faint until pointed at or focused, and fades with the other controls when idle.
imagesArray[]
The gallery to display. Each entry is either a src string or an object of shape { src, alt, caption, srcset, sizes, width, height, thumb, origin }; everything but src is optional. width and height reserve the image's shape while it loads. thumb is a small source for the filmstrip (it falls back to src). origin is the element the picture grows out of on open and back into on close, as an element or a selector; without it the viewer uses the element that was clicked or focused when show() ran, for the image it opened on. Set as a property, or as a JSON attribute for a gallery that is static.
indexnumber0
Index of the image currently displayed. Navigation wraps at both ends, so setting it out of range shows the nearest valid image.
openbooleanfalse
Controls the visible state of the viewer. Set to true to open at the current index and activate the focus trap; set to false to close and restore focus to the previously-focused element.

Methods

show(index?)index?: number
Open the viewer, optionally jumping to a specific image first.
close()
Closes the viewer through the cancelable arc-close contract.
next()
Advances to the next image, wrapping past the end.
prev()
Steps to the previous image, wrapping past the start.

Events

arc-changedetail:{value: number, index: number}
Fired when the displayed image changes. detail.value is the new index.
arc-close
Fired when the lightbox closes. Cancelable: call preventDefault() to veto the close.
arc-open
Fired when the lightbox opens

See also