Native apps have always had smooth transitions between screens. On the web, getting the same effect usually meant a heavy animation library, keeping old and new content in the DOM at the same time, and careful choreography to avoid layout jumps. Multi-page sites could not animate between pages at all: the old page vanished and the new one appeared.

The View Transition API changes that. The browser takes a snapshot of the page before a change, takes another after it, and animates between the two using CSS you control. It works for state changes inside a single-page app, and it also works for ordinary navigations between separate HTML pages.

This article is for front-end developers who want polished transitions without shipping a large animation library. We will start with a single-page example, move on to multi-page sites, then cover shared element transitions, transition types and reduced motion.

How a view transition works

#

Every view transition follows the same steps:

  1. The browser captures a snapshot of the current state.
  2. Your code (or a navigation) updates the DOM.
  3. The browser captures the new state.
  4. It builds a tree of pseudo-elements holding the old and new snapshots, and animates between them.
  5. When the animation ends, the pseudo-elements are removed and the real, updated page is left behind.

The pseudo-element tree looks like this:


_10
::view-transition
_10
└─ ::view-transition-group(root)
_10
└─ ::view-transition-image-pair(root)
_10
├─ ::view-transition-old(root)
_10
└─ ::view-transition-new(root)

By default the whole page is one group called root, and the browser cross-fades the old snapshot into the new one. Everything else in this article is about customising that.

One point worth knowing early: during the transition, the snapshots are images. The page underneath is already updated, but the user sees the animation until it finishes. Keep transitions short so the page does not feel unresponsive.

Single-page apps: document.startViewTransition

#

In a single-page app you control when the DOM changes, so you wrap that change in document.startViewTransition().


_15
function showTab(tabName) {
_15
const update = () => {
_15
document.querySelectorAll('[data-panel]').forEach((panel) => {
_15
panel.hidden = panel.dataset.panel !== tabName;
_15
});
_15
};
_15
_15
// Fall back to an instant update where the API is missing
_15
if (!document.startViewTransition) {
_15
update();
_15
return;
_15
}
_15
_15
document.startViewTransition(update);
_15
}

That is all you need for a cross-fade. The callback can also be async, which is useful when the new content comes from the network:


_10
async function loadArticle(id) {
_10
const transition = document.startViewTransition(async () => {
_10
const res = await fetch(`/api/articles/${id}`);
_10
const article = await res.json();
_10
renderArticle(article);
_10
});
_10
_10
await transition.finished;
_10
console.log('Transition complete');
_10
}

Be careful with that pattern. The browser holds the old snapshot on screen while the callback runs, and the page does not respond to input. If the request is slow, fetch the data first and only start the transition when you are ready to update the DOM.

The ViewTransition object

startViewTransition() returns a ViewTransition object with three promises:

  • updateCallbackDone resolves when your callback has finished.
  • ready resolves when the pseudo-elements exist and the animation is about to start. This is the moment to run custom animations with the Web Animations API.
  • finished resolves when the animation has ended and the new view is fully interactive.

It also has a skipTransition() method, which jumps straight to the end state. Your update callback still runs.


_12
const transition = document.startViewTransition(update);
_12
_12
transition.ready.then(() => {
_12
document.documentElement.animate(
_12
{ clipPath: ['circle(0% at 50% 50%)', 'circle(150% at 50% 50%)'] },
_12
{
_12
duration: 400,
_12
easing: 'ease-out',
_12
pseudoElement: '::view-transition-new(root)',
_12
}
_12
);
_12
});

That example reveals the new page through a growing circle, a common effect for switching between light and dark themes.

Using it with React

In React, the DOM update happens when React commits, not when you call setState. To make sure the update happens inside the transition callback, use flushSync from react-dom:


_14
import { flushSync } from 'react-dom';
_14
_14
function toggleView() {
_14
if (!document.startViewTransition) {
_14
setView((v) => (v === 'grid' ? 'list' : 'grid'));
_14
return;
_14
}
_14
_14
document.startViewTransition(() => {
_14
flushSync(() => {
_14
setView((v) => (v === 'grid' ? 'list' : 'grid'));
_14
});
_14
});
_14
}

Frameworks increasingly offer their own integrations, so check your router or framework docs before wiring this up by hand.

Multi-page apps: cross-document view transitions

#

For a plain multi-page site, you do not write any JavaScript at all. Add this rule to the CSS of both the page you are leaving and the page you are going to:


_10
@view-transition {
_10
navigation: auto;
_10
}

Now, when a user follows a link from one page to another, the browser cross-fades between them instead of flashing to white.

A few rules apply:

  • Both pages must opt in. If only one page has the rule, there is no transition.
  • The navigation must be same-origin. Transitions do not run when navigating to another site.
  • It applies to ordinary navigations such as clicking a link, submitting a form, or using back and forward. It does not run when the user types a URL into the address bar or reloads.
  • If the new page takes too long to load, the browser skips the transition rather than freezing the old page indefinitely.

This is one of the cheapest polish improvements you can make to a server-rendered site, static site or blog, because it needs no client-side routing.

Hooking into cross-document transitions

Two events give you control when you need it:

  • pageswap fires on the old page just before it is replaced.
  • pagereveal fires on the new page before its first render.

Both events have a viewTransition property, which is the ViewTransition object (or null if no transition is running). You can use them to set names or types based on where the user is going:


_10
window.addEventListener('pagereveal', (event) => {
_10
if (!event.viewTransition) return;
_10
_10
const from = navigation.activation?.from?.url;
_10
if (from && new URL(from).pathname === '/') {
_10
event.viewTransition.types.add('from-home');
_10
}
_10
});

That example uses the Navigation API to find the previous URL. Check support for it in your target browsers before you rely on it.

Shared element transitions with view-transition-name

#

The cross-fade is nice, but the real magic is when an element appears to move from one place to another, such as a product thumbnail growing into the hero image on its detail page.

Give the element a view-transition-name:


_10
.product-thumb {
_10
view-transition-name: product-image;
_10
}

On the detail page, give the hero image the same name:


_10
.product-hero {
_10
view-transition-name: product-image;
_10
}

The browser now creates a separate group called product-image. Instead of fading, it animates the position and size of the group from the old element to the new one, and cross-fades the contents.

The rule to remember: each name must be unique on the page at the moment of capture. If two elements share a name, the transition is skipped and an error is logged to the console.

That makes lists tricky. On a page with twenty product cards, you cannot give every image the same name. Set the name only on the one being clicked:


_10
card.addEventListener('click', () => {
_10
card.querySelector('img').style.viewTransitionName = 'product-image';
_10
});

Or give each card a unique name from its ID in your template:


_10
<img class="product-thumb" style="view-transition-name: product-42" src="/img/42.jpg" alt="Blue kettle">

Newer browsers also support view-transition-name: match-element, which generates a unique name for each element automatically for same-document transitions. Check support before depending on it.

Customising the animation

Each named group gets its own pseudo-elements, which you style like any other element:


_22
/* Slow down the shared image */
_22
::view-transition-group(product-image) {
_22
animation-duration: 400ms;
_22
animation-timing-function: cubic-bezier(0.2, 0, 0, 1);
_22
}
_22
_22
/* Slide the rest of the page instead of fading */
_22
@keyframes slide-out {
_22
to { transform: translateX(-30px); opacity: 0; }
_22
}
_22
_22
@keyframes slide-in {
_22
from { transform: translateX(30px); opacity: 0; }
_22
}
_22
_22
::view-transition-old(root) {
_22
animation: 200ms ease-in both slide-out;
_22
}
_22
_22
::view-transition-new(root) {
_22
animation: 300ms ease-out both slide-in;
_22
}

A useful trick is to give a site header its own name so it stays still while the content around it animates:


_10
.site-header {
_10
view-transition-name: site-header;
_10
}
_10
_10
::view-transition-group(site-header) {
_10
animation: none;
_10
}

Transition types: forwards and backwards

#

Often you want different animations depending on direction: slide left when going forward, right when going back. View transition types let you tag a transition and target it in CSS.

In a single-page app, pass types when you start the transition:


_10
document.startViewTransition({
_10
update: () => goToStep(next),
_10
types: [next > current ? 'forward' : 'backward'],
_10
});

Then select on the active type with the :active-view-transition-type() pseudo-class:


_10
html:active-view-transition-type(forward) {
_10
&::view-transition-old(root) { animation-name: slide-out-left; }
_10
&::view-transition-new(root) { animation-name: slide-in-right; }
_10
}
_10
_10
html:active-view-transition-type(backward) {
_10
&::view-transition-old(root) { animation-name: slide-out-right; }
_10
&::view-transition-new(root) { animation-name: slide-in-left; }
_10
}

For cross-document transitions, you can list types in the at-rule, or add them in the pageswap and pagereveal events as shown earlier:


_10
@view-transition {
_10
navigation: auto;
_10
types: slide;
_10
}

Types arrived after the core API, so support is narrower. Check before relying on them, and make sure the default transition still looks fine without them.

Respecting prefers-reduced-motion

#

Some users find movement on screen uncomfortable or disorientating, and set a reduced motion preference in their operating system. Large sliding or zooming transitions are exactly the sort of motion they want to avoid.

The simplest approach is to turn off view transition animations when that preference is set:


_10
@media (prefers-reduced-motion: reduce) {
_10
::view-transition-group(*),
_10
::view-transition-old(*),
_10
::view-transition-new(*) {
_10
animation: none !important;
_10
}
_10
}

For cross-document transitions, you can opt in only when motion is acceptable:


_10
@media (prefers-reduced-motion: no-preference) {
_10
@view-transition {
_10
navigation: auto;
_10
}
_10
}

A softer option is to keep a quick cross-fade for reduced motion users and drop only the sliding and scaling. A short fade is generally considered gentle, but the safest default is still to respect the preference fully.

In JavaScript, you can check the same preference and skip the transition altogether:


_10
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
_10
_10
if (reduceMotion || !document.startViewTransition) {
_10
update();
_10
} else {
_10
document.startViewTransition(update);
_10
}

Performance notes

#

View transitions are cheap compared to animating real DOM elements, because the browser animates flat snapshots on the compositor. Still, a few habits help:

  • Keep them short. 200 to 400 milliseconds is plenty. During the animation, the user is looking at images and cannot interact with the new page.
  • Name only what moves. Every named element creates its own group and snapshot. Dozens of named elements cost memory and can make the transition stutter on low-end devices.
  • Do not block on the network. In single-page apps, fetch first, then start the transition. In multi-page apps, a fast server response matters more than ever, because a slow page will see the transition skipped.
  • Avoid layout shifts in the new page. If the new page's images have no dimensions, the shared element may animate to the wrong place. Set width and height on images.

Browser support

#

At the time of writing (late 2026):

  • Same-document transitions (document.startViewTransition) are Baseline. They have been in Chrome and Edge since version 111, in Safari since 18, and in Firefox since 144, released in October 2025.
  • Cross-document transitions (@view-transition) work in Chrome and Edge from version 126 and in Safari from 18.2. Firefox has not fully shipped them yet; its work is tracked in Mozilla's bug tracker, so check caniuse for the current status.
  • Transition types came later than the core API. Firefox added same-document types in version 147.

The good news is that view transitions are a natural progressive enhancement. In a browser without support, @view-transition is ignored and the navigation happens instantly, exactly as it does today. In JavaScript, a feature check on document.startViewTransition lets you fall back to a plain update.

When not to use it

#
  • Frequent, rapid updates. Typing in a search box, dragging a slider or live data updates should not trigger a view transition each time. Starting a new transition skips the previous one, and the result feels jittery.
  • Slow updates. If the DOM update depends on a slow network request, the page appears frozen while the old snapshot is shown. Show a loading state instead.
  • Long, decorative sequences. Transitions should help users understand what changed. If an animation exists only to look impressive, it will soon feel like it is slowing people down.
  • Cross-origin navigation. Cross-document transitions only work within the same origin, so they cannot be used between your marketing site and an app on a different domain.
  • Interactive animation. Because the transition animates snapshots, you cannot interact with the content mid-animation. For gestures such as swipe-to-go-back, where the user controls progress, a different technique may suit better.

Wrapping up

#
  • Wrap single-page DOM updates in document.startViewTransition() and feature-check it for a safe fallback.
  • Add @view-transition with navigation: auto to both pages for cross-document transitions on multi-page sites, with no JavaScript.
  • Use view-transition-name for shared element transitions, and keep each name unique on the page.
  • Style the ::view-transition-old, ::view-transition-new and ::view-transition-group pseudo-elements to customise the animation, and use types for direction-aware effects.
  • Respect prefers-reduced-motion, keep transitions short, and treat the whole feature as progressive enhancement.
#
file under:
CSS

Was this article helpful?

About the author

Danny Engineering

A software engineer with a strong belief in human-centric design and driven by a deep empathy for users. Combining the latest technology with human values to build a better, more connected world.