View transitions

The View Transitions API animates between two states of a page: the browser captures the old view, you update the DOM, and it morphs and cross-fades to the new one.

View transitions are a browser feature for animating from one state of a page to the next without measuring anything yourself. Call document.startViewTransition() with a function that updates the DOM; the browser takes a snapshot before and after, then animates between them with a cross-fade by default.

Give an element the same view-transition-name in both states and the browser morphs it from its old position and size to the new one, the way a thumbnail grows into a full image. The animations are ordinary CSS on ::view-transition-old() and ::view-transition-new(), so you can change their duration and easing.

Same-page transitions work in current Chrome, Edge and Safari; transitions between whole pages use the @view-transition rule. Always check that the method exists and update the DOM directly when it does not, and shorten or skip the animation under prefers-reduced-motion.

function go(update) {
  if (!document.startViewTransition) return update();
  document.startViewTransition(update);
}

/* the same name in both states makes the browser morph it */
.thumb, .hero-image { view-transition-name: product-photo; }
::view-transition-group(product-photo) { animation-duration: 400ms; }

Related terms