StealThis .dev

View Transitions Gallery

A photo gallery that morphs a clicked thumbnail into a full-bleed detail hero using the View Transitions API, with shared-element name matching, crossfading metadata, keyboard navigation, and a graceful crossfade-free fallback when the browser lacks support.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

This component is a compact curated gallery that demonstrates the browser’s native View Transitions API (document.startViewTransition). Click any thumbnail and the DOM swaps from a masonry grid into a single detail view — but instead of a jarring reflow, the clicked image smoothly morphs into a large hero while its caption, palette, and metadata crossfade into place. The trick is assigning a matching view-transition-name to the thumbnail and the hero so the browser treats them as the same “shared element” across two document states.

The interaction is fully keyboard-driven: arrow keys move focus, Enter opens, and Escape returns to the grid with the reverse transition playing automatically. A live status line reports whether the API is active, and the whole experience degrades gracefully — if startViewTransition is missing, the state change still happens instantly with a light opacity crossfade, so nothing breaks on older engines.

Under the hood it showcases three pieces of the platform: the imperative startViewTransition(callback) entry point, the ::view-transition-group/::view-transition-old/::view-transition-new pseudo-elements for tuning timing and easing, and dynamic view-transition-name assignment so only the relevant element animates. It is a self-contained, dependency-free reference for building app-like page-to-page motion with vanilla JS and CSS.