View Transitions API — Web Animation

The View Transitions API animates the move between two states of a page. document.startViewTransition(update) captures the old state, runs update (the DOM…

Before-and-after photos of a room being renovated are made like this: the photographer shoots the old room, the builders change what's inside, then the photographer shoots again. The two photos are stacked, and the old photo is faded into the new one. The View Transitions API does exactly that for your DOM (the structure of elements on the page). The browser is the photographer, your code that changes the DOM is the builders, and the fade from the old capture to the new capture is the animation. The result: the move between two states of a page is animated, without you writing an exit and an entry animation for each piece.

document.startViewTransition(update)

The function changePhoto below changes the gallery photo with a view transition:

function changePhoto(i) {
  const update = () => renderPhoto(i);    // change the DOM here
  if (!document.startViewTransition) {    // older browser: just change it
    update();
    return;
  }
  document.startViewTransition(update);
}

What the browser does, in order:

  1. Captures the old state (old).
  2. Calls update, and the DOM changes. Meanwhile the page's rendering is held (nothing changes on screen), so don't put a slow fetch (a request for data from a server) inside update.
  3. Captures the new state (new).
  4. Animates the old capture into the new one. The default animation is a 250 ms crossfade: the old capture fades out while the new one appears. We measured 250 ms in Chromium 147, WebKit 26.4 and Firefox 146.

startViewTransition returns a ViewTransition object with three Promises: updateCallbackDone (the DOM has changed), ready (the animation is about to start), and finished (the animation is over). When we changed the photo in Chromium, the update was done at 10 ms, ready at 14 ms, and finished at 275 ms. There's also skipTransition() to skip the animation.

The if (!document.startViewTransition) check is a must. Older browsers (Safari before 18, Firefox before 144) don't have this method. If you call it directly in an older browser, the browser throws a TypeError, and the DOM never changes. With the check, older browsers still show the new content, just without the animation.

The ::view-transition tree

During the animation, the browser builds a tree (a nested structure) of pseudo-elements on top of the page. Pseudo-elements are parts the browser creates that aren't in your HTML, but you can style them with CSS:

::view-transition
└─ ::view-transition-group(root)
   └─ ::view-transition-image-pair(root)
      ├─ ::view-transition-old(root)    the old capture, fading out
      └─ ::view-transition-new(root)    the new capture, fading in

root is the whole page. An element given its own view-transition-name is taken out of the root capture and gets a branch of its own. That branch is a group that moves and resizes from the old position to the new one, and the group holds the element's old and new captures. Here is Mrs. Sri's gallery with a 300 ms ease-in-out slide, plus the total rising 4 px in 200 ms:

.photo { view-transition-name: photo; }
.total { view-transition-name: total; }

@keyframes slide-out { to   { opacity: 0; transform: translateX(-24px); } }
@keyframes slide-in  { from { opacity: 0; transform: translateX(24px); } }
@keyframes fade      { to   { opacity: 0; } }
@keyframes rise      { from { opacity: 0; transform: translateY(4px); } }

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(photo) { animation: 300ms ease-in-out both slide-out; }
  ::view-transition-new(photo) { animation: 300ms ease-in-out both slide-in; }
  ::view-transition-old(total) { animation: 150ms ease-in both fade; }
  ::view-transition-new(total) { animation: 200ms ease-out both rise; }
}

One name, one element

Take a guess first: in the Terrace Room gallery, the big photo has view-transition-name: photo. You want the selected thumbnail (a small photo) to look like it flies into the big photo, so you give that thumbnail view-transition-name: photo too. Then you call startViewTransition to change the photo. What happens?

The answer: the transition is aborted, because a view-transition-name must be unique in each capture. We gave the name photo to the big photo and the selected thumbnail at the same time, then called startViewTransition. This is the result:

Browser ready rejects with InvalidStateError
Chromium 147 "Transition was aborted because of invalid state", plus a console error: "Unexpected duplicate view-transition-name: photo"
WebKit 26.4 "Multiple elements found with view-transition-name: photo"
Firefox 146 "Duplicate view-transition-name value while capturing old state"

The update callback still runs, the DOM still changes, and finished still settles. Only the animation is gone, for every element, not just the photo.

The effect of a thumbnail flying into the big photo is still possible. Use the same name for the old element in the old capture (the thumbnail, before) and the new element in the new capture (the big photo, after), but never on two elements at the same time. For a list, give each element a different name (photo-1, photo-2), or use view-transition-name: match-element, which makes the browser give each element a unique name itself (Chrome 137, Safari 18.4, Firefox 144).

Between pages: @view-transition

For ordinary navigation between two pages (clicking a link that loads a new page, not an SPA that changes the page's content with JavaScript), this CSS on both pages is enough. Both pages must have the same origin, which means they come from the same site:

@view-transition {
  navigation: auto;
}

Its support differs from the single-page version. This is MDN data as of October 2026, checked against our tests:

Single page (startViewTransition) Between pages (@view-transition)
Chrome, Edge 111 126
Safari 18 18.2
Firefox 144 (October 2025) not yet; our Firefox 146 drops the rule from cssRules

Reduce motion

The browser does not turn off view transitions on its own. With prefers-reduced-motion: reduce ("Reduce motion" turned on), all three browsers still played the built-in 250 ms animations (we measured). That's why the slide above sits inside no-preference, the media query for people who have not turned on "Reduce motion". For reduce, write this:

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*) { animation: none; }               /* no movement in position or size */
  ::view-transition-old(*),
  ::view-transition-new(*)   { animation-duration: 150ms; }     /* keep a short fade */
}

* means every name. A rule with a specific name (photo) is stronger than *, so this reduce rule can't beat the photo's slide. That's why the photo's slide has to be wrapped in no-preference.

⚠️ What aborts or stalls a view transition

TL;DR: The View Transitions API animates the move between two states of a page. document.startViewTransition(update) captures the old state, runs update (the DOM changes), captures the new state, then animates the old capture into the new one (a built-in 250 ms crossfade). Always check if (!document.startViewTransition) first, and call update directly as the fallback for older browsers. An element with a view-transition-name gets its own branch in the pseudo-element tree ::view-transition-group / -image-pair / -old / -new, styled with CSS: the gallery slides 300 ms ease-in-out, the total rises 4 px in 200 ms. The name must be unique: two elements with the same name abort the whole transition with InvalidStateError (the DOM still changes). To make it look like one element moving, use the same name on the element before and the element after. Single page: Chrome 111, Safari 18, Firefox 144. Between pages with @view-transition { navigation: auto; } on both pages: Chrome 126, Safari 18.2, Firefox not yet. The browser doesn't reduce motion on its own: write ::view-transition-group(*) { animation: none } and a 150 ms fade under prefers-reduced-motion: reduce.

⚡ Before and after photos

Write:

function changePhoto(i) {
  const update = () => renderPhoto(i);    // change the DOM here
  if (!document.startViewTransition) {    // older browser: just change it
    update();
    return;
  }
  document.startViewTransition(update);
}

Meaning: The function changePhoto changes the gallery photo. document.startViewTransition(update) makes the browser capture the old state, run update (which changes the DOM), capture the new state, then fade the old capture into the new one in 250 ms. Check first that startViewTransition exists. Older browsers don't have this method, and with the check they still get the new content.

⚡ A branch of its own

Write:

.photo { view-transition-name: photo; }

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(photo) { animation: 300ms ease-in-out both slide-out; }
  ::view-transition-new(photo) { animation: 300ms ease-in-out both slide-in; }
}

Meaning: During a transition, the browser captures the whole page as root. An element with a view-transition-name (here .photo, named photo) is captured on its own and gets a branch of its own, separate from root. ::view-transition-old(photo) is that element's old capture, and ::view-transition-new(photo) its new one. Both can be animated with ordinary CSS, here with a 300 ms slide out and slide in, only when "Reduce motion" is not turned on (no-preference).

⚡ One name, one element

Guess first: the big photo and the selected thumbnail (a small photo) both have view-transition-name: photo. What happens when the photo changes?

The transition is aborted. ready (a Promise that settles when the animation is ready to start) rejects with InvalidStateError, and the animation is gone for every element. The DOM still changes.

Meaning: A name must be unique in each capture. To make a thumbnail look like it flies into the big photo, use the same name for the thumbnail in the old capture and the big photo in the new capture. Never put it on two elements at the same time.

⚡ Reduce motion isn't automatic

Meaning: With prefers-reduced-motion: reduce ("Reduce motion" turned on), the browser still plays the built-in 250 ms view transition animations. Write the reduce rules yourself: ::view-transition-group(*) { animation: none; } (no movement of position and size, for every name) and a short 150 ms fade.

What you will learn