Gallery to Slideshow
CSS thumbnail grid switching to a sliding-window slideshow — cubic transitions, arrow + dot navigation, instant toggle.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Cards has 43 effects, including 6 free. Explore the category →
3 usage examples



How it works
The gallery/slideshow switch is entirely CSS-driven: setGalleryMode() adds .hidden to .gallery-grid-mode and .active to .gallery-slideshow-mode, toggling opacity and pointer-events in 400 ms — no JS animation, just declared CSS transitions.
The slideshow maintains a 3-class sliding window: .slideshow-slide.prev (translateX(-120%) scale(0.8)), .slideshow-slide.current (translateX(0) scale(1)), .slideshow-slide.next (translateX(120%) scale(0.8)). On each navigation, updateSlideshow(root) strips prev/current/next classes from all .slideshow-slide elements in the DOM and reassigns them using modulo arithmetic on their count — without touching their HTML content or inline styles. The .6s cubic-bezier(.4,0,.2,1) transition declared on the slides does the rest. Slides with no class stay hidden (opacity: 0; pointer-events: none).
The grid is a CSS Grid repeat(3, 1fr) over two rows with a 4 px gap. Thumbnails (.gallery-thumb) and slides (.slideshow-slide) are <div> elements with an inline background by default — replace them with <img>, <picture> or any other HTML for real photos or rich content. Slides can contain any HTML: the JS only modifies their CSS classes.
Accessibility
- No
prefers-reduced-motionblock is present in the CSS or JS — transitions run even when the user has requested reduced motion. Compensate in production by adding@media (prefers-reduced-motion: reduce) { .slideshow-slide { transition: none } }. - Arrow buttons carry
aria-label="Previous slide"/aria-label="Next slide"— keyboard and screen-reader accessible. - Navigation dots are native
<button>elements witharia-label="Go to slide N"— focusable via Tab, activatable via Enter or Space. - Gallery / Slideshow toggle buttons are native
<button>elements in the normal tab order, no extraroleattribute needed. - No
roleoraria-labelis set on the component wrapper — add one in production to identify the widget to assistive technologies.
Browser compatibility
Requires CSS Grid, CSS transitions, and CSS transforms — available in all modern browsers since 2017. Zero external dependencies.
Without CSS transition support, the gallery/slideshow switch is instant but functional. Without JS, the toggle buttons are inoperable and the grid stays in fixed gallery mode.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="demo-preview">
<div class="morph-toggle-group">
<button class="morph-toggle active" onclick="setGalleryMode(this,'gallery')">Gallery</button>
<button class="morph-toggle" onclick="setGalleryMode(this,'slideshow')">Slideshow</button>
</div>
<div class="gallery-slideshow-wrapper">
<div class="gallery-grid-mode">
<div class="gallery-thumb" style="background:…"></div>
<!-- ×6 thumbnails -->
</div>
<div class="gallery-slideshow-mode">
<div class="slideshow-slide current" style="background:…"></div>
<div class="slideshow-slide next" style="background:…"></div>
<div class="slideshow-slide" style="background:…"></div>
<!-- ×3 more slides, last one with class="slideshow-slide prev" -->
<button class="slideshow-arrow left" onclick="slideshowPrev(this)" aria-label="Previous">‹</button>
<button class="slideshow-arrow right" onclick="slideshowNext(this)" aria-label="Next">›</button>
<div class="slideshow-nav"><!-- N× .slideshow-dot with onclick="slideshowGo(this, N)" --></div>
</div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
| `.slideshow-slide` content | inline gradient background | Replace style="background:…" with an <img style="width:100%;height:100%;object-fit:cover"> tag or any other HTML — the JS never modifies slide content, only their CSS classes. |
| `.gallery-slideshow-wrapper` height | 150px | Total height of the component. Set to 100vh for a full-screen slideshow, or match your content column height. |
| `.slideshow-slide` transition | .6s cubic-bezier(.4,0,.2,1) | Duration and curve of the slide animation. .35s ease for more responsiveness, 1s for a cinematic transition. |
| `.gallery-grid-mode` grid-template-columns | repeat(3, 1fr) | Number of grid columns. repeat(2, 1fr) for 4 images over 2 rows, repeat(4, 1fr) for 8 images over 2 rows. |
| `--primary` (`:root`) | #6366f1 | Accent color for the active toggle button (Gallery / Slideshow). Replace with your brand color. |
| `.slideshow-slide` border-radius | 10px | Corner radius of slides in full-frame view. 0 for edge-to-edge slides. |
| `.gallery-thumb` border-radius | 4px | Corner radius of thumbnails in the grid. 0 for strict square thumbnails. |
FAQ
setGalleryMode with a button from the instance: var btn = root.querySelector(".morph-toggle"); setGalleryMode(btn, 'slideshow'); where root is the target .fx-0160-root. Or manipulate classes directly: root.querySelector('.gallery-grid-mode').classList.add('hidden'); root.querySelector('.gallery-slideshow-mode').classList.add('active'); then call btn.click() on the Slideshow button to sync the active state..gallery-grid-mode, replace style="background:…" on each .gallery-thumb with an <img style="width:100%;height:100%;object-fit:cover"> tag. In .gallery-slideshow-mode, replace the style="background:…" on each .slideshow-slide with the same image content — or any other HTML. The JS never touches slide content, only their CSS classes..gallery-thumb elements to .gallery-grid-mode and the same number of .slideshow-slide elements to .gallery-slideshow-mode. Add matching .slideshow-dot buttons to .slideshow-nav (update their onclick="slideshowGo(this, N)" with the correct index). updateSlideshow() computes prev/current/next indices using modulo on the slide count — no other changes needed.