A view transition animates between two states of the page without you keeping both in the DOM. The browser takes pictures and animates those.
Within a page, document.startViewTransition(updateCallback):
- At the next rendering step, captures the old state: an image of the page, plus a separate image and box of every element with a
view-transition-name. - Pauses rendering, so the user keeps seeing the old frame, and calls your callback, which changes the DOM (sync or async).
- When the callback's promise settles, captures the new state and builds a pseudo-element tree over the page:
::view-transition›::view-transition-group(name)›::view-transition-image-pair(name)›::view-transition-old(name)and::view-transition-new(name). The root is namedrootby default. - Resumes rendering and animates. By default, old fades out, new fades in, and each group animates from the old size and position to the new one. They're ordinary CSS animations, so you restyle them with
animationon those pseudo-elements.
The returned ViewTransition has three promises: updateCallbackDone (the DOM change finished), ready (pseudo-elements exist, animations about to run) and finished. skipTransition() skips the animation; the callback still runs.
Across pages, add @view-transition { navigation: auto; } to both documents. On a same-origin navigation the old page is captured before it's swapped out, and the new page animates in on its first rendering opportunity. Names match across the two pages. pageswap (old page) and pagereveal (new page) expose the ViewTransition for customising. Reloads, cross-origin navigations and URLs typed in the address bar don't transition; back and forward do.
Support: same-document since Chrome 111, Firefox 144 and Safari 18; cross-document in Chrome 126 and Safari 18.2, not in Firefox 159.