Same-document View Transitions let you animate between two DOM states with one call to document.startViewTransition(). Match elements across states with view-transition-name and customize the cross-fade with the ::view-transition-old(name) and ::view-transition-new(name) pseudo-elements. Build a transition below and run it in a live sandbox.
::view-transition-old/new keyframes. Tweak below.view-transition-name are matched and morph as a pair. Names must be unique on the page at any moment.@media (prefers-reduced-motion: no-preference) so motion-sensitive users get a calmer change.startViewTransition(). The transition uses the CSS below.
Support: Same-document View Transitions shipped in Chrome 111 (March 2023), Edge 111, and Safari 18 (Sep 2024). Firefox 134+ behind dom.viewTransitions.enabled. Unsupported browsers run the callback synchronously without animation — feature-detect with 'startViewTransition' in document.
document.startViewTransition(updateDOM) screenshots the page, runs updateDOM, screenshots again, and animates between snapshots.view-transition-name: hero on the source and on the destination element. The browser ties them into a single pair (called a group) and animates position + size automatically.::view-transition-old(name) and ::view-transition-new(name) to override the default cross-fade — slide, flip, zoom, anything CSS animations can do.contain: layout if the element jumps around layout.prefers-reduced-motion. Wrap your custom keyframes in a motion-safe media query so vestibular users get the default fade (or no animation) instead.