View Transitions API
document.startViewTransition() captures rasterized textures of the current DOM, runs your update callback, and animates a ::view-transition pseudo-element tree between the old snapshot and the new live DOM, turning state swaps into smooth hero morphs without duplicate DOM nodes.
View Transition Snapshot Lifecycle
Step through how the engine captures, swaps, and animates old and new DOM states.
Engine freezes rendering and captures GPU textures for root and every unique view-transition-name.
const vt = document.startViewTransition(() => renderNextView());- renderingPaused
- true
- oldSnapshots
- 2
- domMutated
- false
Under the Hood
Instead of keeping two competing UI trees alive in memory during a route change, the engine takes a photograph of the outgoing room, swaps the furniture, and cross-fades the photo into reality.
- Snapshot Phase: Elements with a unique
view-transition-nameare captured during Paint & Rasterization as isolated textures. - Mutation Phase: Rendering pauses while the callback mutates the DOM.
- Pseudo-Tree Morph: The engine injects
::view-transition-group,-old, and-newpseudo-elements over the viewport, animating size, transform, and opacity on GPU Compositor Layers.
function navigateToCard(card, nextHtml) {
if (!document.startViewTransition) return (main.innerHTML = nextHtml);
card.style.viewTransitionName = 'active-card';
const vt = document.startViewTransition(() => {
main.innerHTML = nextHtml;
});
vt.finished.finally(() => { card.style.viewTransitionName = ''; });
}Problem Genealogy
- 2015–2022: Shared-element transitions in SPAs required FLIP measurements, cloning DOM nodes into portals, and manual cleanup.
- 2023–2025: View Transitions Level 1 standardized native snapshot-and-morph transitions for same-document updates.
Production Pitfalls
- Duplicate
view-transition-name: Two visible elements with the sameview-transition-nameabort the entire transition. - Async network calls inside the callback: Awaiting
fetch()insidestartViewTransition()freezes user input until the network responds.
- When not to use View Transitions: Avoid wrapping high-frequency micro-interactions (hover states, typing) in
startViewTransition(); reserve it for route or panel transitions, and gate motion behind User-Preference Media Queries (prefers-reduced-motion).
Connections & Logical Next Steps
View transitions capture rasterized GPU snapshots of old and new element states.
The ::view-transition pseudo-element tree animates captured textures on the compositor.
Root morph transitions must respect prefers-reduced-motion: reduce to avoid vestibular discomfort.
WAAPI animates live DOM properties on one tree, whereas View Transitions crossfade rasterized old/new snapshots.