Thumbnail Gallery
Show product photos with a row of thumbnails that pick the photo. setIndex() scrolls to the photo of the clicked thumbnail, and the indexchange event marks the current thumbnail after a click, a swipe, or a button.
The thumbnails replace the page dots, which no-indicators hides. aria-current tells screen readers which thumbnail shows. Swap the gradient tiles for <img> elements with your photos.
Code
The following example assumes that you have imported the component and set up the theme.
<div class="product-gallery">20 collapsed lines
<sv-carousel class="photos" aria-label="Product photos" no-indicators> <div class="photo" style="--hue: 30" aria-label="Front view"></div> <div class="photo" style="--hue: 90" aria-label="Side view"></div> <div class="photo" style="--hue: 150" aria-label="Back view"></div> <div class="photo" style="--hue: 210" aria-label="Detail of the fabric"></div> <div class="photo" style="--hue: 270" aria-label="Worn outdoors"></div> </sv-carousel>
<div class="thumbnails"> <button class="thumbnail" style="--hue: 30" aria-current="true" aria-label="Front view" ></button> <button class="thumbnail" style="--hue: 90" aria-label="Side view"></button> <button class="thumbnail" style="--hue: 150" aria-label="Back view"></button> <button class="thumbnail" style="--hue: 210" aria-label="Detail of the fabric"></button> <button class="thumbnail" style="--hue: 270" aria-label="Worn outdoors"></button> </div></div>
<script type="application/x-typescript" module>13 collapsed lines
const gallery = document.querySelector(".product-gallery")!; const photos = gallery.querySelector<Carousel>(".photos")!; const thumbnails = [...gallery.querySelectorAll<HTMLButtonElement>(".thumbnail")];
for (const [index, thumbnail] of thumbnails.entries()) { thumbnail.addEventListener("click", () => photos.setIndex(index)); }
photos.addEventListener("indexchange", () => { for (const [index, thumbnail] of thumbnails.entries()) { thumbnail.ariaCurrent = index === photos.index ? "true" : null; } });</script>
<style>41 collapsed lines
.product-gallery { display: grid; gap: 0.75rem; max-inline-size: 32rem; margin-inline: auto;
.photo, .thumbnail { background-image: linear-gradient( 135deg, oklch(80% 0.1 var(--hue)), oklch(50% 0.14 calc(var(--hue) + 50)) ); border-radius: var(--sv-bdr-rad-md); }
.photo { aspect-ratio: 4 / 3; }
.thumbnails { display: flex; gap: 0.5rem; justify-content: center; }
.thumbnail { flex: 0 1 4.5rem; min-inline-size: 0; aspect-ratio: 4 / 3; padding: 0; cursor: pointer; border: 2px solid transparent; opacity: 0.6;
&[aria-current="true"] { border-color: var(--sv-accent); opacity: 1; } } }</style>