Component API

<photo-gallery>

Open live example

Responsive, accessible image carousel composed from declarative
gallery-item children.

Install

import "@f-ewald/components/photo-gallery.js";

Usage

<photo-gallery delay="5000" show-counter show-indicators>
  <gallery-item
    src="/photos/coast.jpg"
    alt="Rocky California coastline"
    caption="California coast"
  >
    <gallery-item-variant
      media="(max-width: 640px)"
      srcset="/photos/coast-portrait.jpg"
    ></gallery-item-variant>
  </gallery-item>
  <gallery-item src="/photos/bridge.jpg" alt="Golden Gate Bridge"></gallery-item>
</photo-gallery>
<script type="module">
  document.querySelector("photo-gallery").addEventListener("slide-change", (event) => {
    console.log(event.detail.currentIndex);
  });
</script>

Attributes / properties

PropertyAttributeTypeDefaultDescription
currentIndexcurrent-indexnumber0Zero-based active image index.
delaydelaynumber0Autoplay interval in milliseconds. Set to zero to disable autoplay.
showControlsshow-controlsbooleantrueWhether previous and next buttons are shown.
showCountershow-counterbooleanfalseWhether a current/total counter is shown.
showIndicatorsshow-indicatorsbooleanfalseWhether clickable slide indicators are shown.
showAutoplayControlshow-autoplay-controlbooleantrueWhether autoplay includes a built-in pause/play control.
pausedpausedbooleanfalseWhether autoplay is explicitly paused.
aspectRatioaspect-ratiostring"16 / 9"CSS aspect ratio used by the image viewport.
objectFitobject-fitPhotoGalleryObjectFit"cover"How images fit within the stable viewport.

Events

EventDescription
slide-changeThe active image changed.

Slots

SlotDescription
(default)Declarative gallery-item elements rendered as slides.

CSS custom properties

Custom property
--ui-border
--ui-focus-ring
--ui-font
--ui-font-size
--ui-font-size-sm
--ui-line-height-tight
--ui-on-accent
--ui-overlay
--ui-primary
--ui-radius
--ui-radius-sm
--ui-surface
--ui-surface-muted
--ui-text
--ui-text-muted