The View Transitions API: Smooth Page Transitions for Any Website
Animate between pages and UI states with one CSS rule or one JavaScript call, in single-page apps and plain multi-page sites
App-Like Transitions Without an Animation Library
Native apps animate between screens: a thumbnail grows into a full photo, a list item slides into a detail view. On the web, building that used to mean keeping both states in the DOM at once, measuring positions and running hand-tuned animations, so most sites simply cut instantly from one page to the next.
The View Transitions API makes the browser do the hard part. It takes a snapshot of the page, lets you update the DOM (or navigate to a new page), takes a snapshot of the result, and animates between the two. By default you get a smooth cross-fade. With a few lines of CSS you get slides, morphs and shared-element transitions.
There are two flavours:
- Same-document transitions for single-page apps and in-page state changes, triggered with
document.startViewTransition(). Supported in Chrome and Edge 111+, Safari 18+ and Firefox 144+. - Cross-document transitions for ordinary multi-page sites, enabled with one CSS rule and no JavaScript. Supported in Chrome and Edge 126+ and Safari 18.2+. Check Firefox's status on Can I use.
Both are progressive enhancements. Browsers without support simply update the page without animation, so there is little reason not to use them. This guide assumes you know CSS animations and basic DOM manipulation.
How a View Transition Works
Every view transition follows the same four steps:
- The browser captures a snapshot of the old state, an image of the page and of any elements you named.
- Your update runs: a callback that changes the DOM, or a navigation to a new page. Rendering is paused while it runs, so the user never sees a half-updated page.
- The browser captures the new state as a live representation.
- It builds a tree of pseudo-elements on top of the page and animates from old to new.
The pseudo-element tree looks like this:
::view-transition
::view-transition-group(root)
::view-transition-image-pair(root)
::view-transition-old(root) /* static snapshot of the old page */
::view-transition-new(root) /* live view of the new page */root is the default group for the whole page. Every element you give a view-transition-name gets its own group alongside it. The default animation fades ::view-transition-old out and ::view-transition-new in, while ::view-transition-group animates size and position from the old box to the new one. That last part is what makes shared-element "morphs" possible.
Because these are normal pseudo-elements running normal CSS animations, you customise transitions with the CSS you already know.
Same-Document Transitions in a Few Lines
Wrap any DOM update in document.startViewTransition(). Always feature-detect, so older browsers still get the update:
function updateView(updateDom) {
if (!document.startViewTransition) {
updateDom();
return;
}
document.startViewTransition(() => updateDom());
}
// Example: switching tabs
tabButton.addEventListener("click", () => {
updateView(() => {
currentPanel.hidden = true;
nextPanel.hidden = false;
});
});The callback can be async. The browser waits for the returned promise before capturing the new state, which lets you fetch data first. Keep it fast, though: the page is visually frozen while the callback runs.
The ViewTransition object
startViewTransition() returns an object with three promises and a method:
updateCallbackDoneresolves when your DOM update has finished.readyresolves when the pseudo-elements exist and the animation is about to start. This is where you can run Web Animations API code against the pseudo-elements.finishedresolves when the animation has ended and the new state is fully interactive.skipTransition()cancels the animation but still applies the update.
Cross-Document Transitions for Multi-Page Sites
For a traditional site where every link loads a new HTML page, add this rule to the CSS of both the page you leave and the page you arrive on:
@view-transition {
navigation: auto;
}That is the whole opt-in. Same-origin link clicks, form submissions and back/forward navigations now cross-fade between pages instead of flashing white. There is no JavaScript API to call.
The rules
- Same-origin only. Navigating from
blog.example.comtowww.example.comdoes not trigger a transition, and neither does a redirect through another origin. - Both pages must opt in. If the destination page lacks the rule, there is no transition.
- Slow navigations are skipped. If the new page takes too long to become ready (around four seconds in Chrome), the browser skips the transition with a
TimeoutError.
Waiting for important content
By default the new page is captured as soon as it can first render. If the element you want to morph, say a hero image, arrives later in the HTML, block rendering until it is parsed:
<link rel="expect" href="#hero" blocking="render">Use this sparingly. Blocking rendering delays First Contentful Paint and Largest Contentful Paint, so measure the impact before shipping it.
pageswap and pagereveal
For dynamic behaviour, such as setting names based on which link was clicked, cross-document transitions fire pageswap on the old page and pagereveal on the new one. Each event has a viewTransition property (null if no transition is running). Register pagereveal in a classic, render-blocking script in the <head>; module, async and defer scripts run too late.
Customising the Animation
Target the pseudo-elements to replace the default cross-fade. This slides the old page out to the left and the new page in from the right:
@keyframes slide-out { to { transform: translateX(-30%); opacity: 0; } }
@keyframes slide-in { from { transform: translateX(30%); opacity: 0; } }
::view-transition-old(root) {
animation: 250ms ease-in both slide-out;
}
::view-transition-new(root) {
animation: 250ms ease-out both slide-in;
}To change the timing of every group at once, use the * wildcard: ::view-transition-group(*) { animation-duration: 300ms; }.
Keep headers and navigation still
A persistent header looks wrong when it fades with the rest of the page. Give it its own name, and it is captured separately. Because it has the same position on both pages, it simply stays put:
.site-header {
view-transition-name: site-header;
}Direction-Aware Transitions With Types
"Next" and "previous" usually deserve different animations. Transition types label a transition so CSS can react to it.
function go(direction, update) {
if (!document.startViewTransition) return update();
document.startViewTransition({ update, types: [direction] });
}
nextButton.onclick = () => go("forwards", showNextSlide);
prevButton.onclick = () => go("backwards", showPreviousSlide);html:active-view-transition-type(forwards) {
&::view-transition-old(root) { animation-name: slide-out-left; }
&::view-transition-new(root) { animation-name: slide-in-right; }
}
html:active-view-transition-type(backwards) {
&::view-transition-old(root) { animation-name: slide-out-right; }
&::view-transition-new(root) { animation-name: slide-in-left; }
}For cross-document transitions, list types in the at-rule, @view-transition { navigation: auto; types: slide; }, or set them in pageswap and pagereveal handlers through event.viewTransition.types.
The example uses native CSS nesting to keep the type rules together.
React and Next.js: What Actually Works
Framework users run into two surprises.
Cross-document rules don't apply to client-side navigation
@view-transition { navigation: auto; } only affects real browser navigations. In a single-page app, including Next.js <Link> navigations, the browser never loads a new document. The URL changes and the framework re-renders in place, so you need same-document transitions.
React must update the DOM synchronously
startViewTransition() captures the new state as soon as your callback returns. React batches state updates and renders later, so the snapshot would show the old UI. Force the update to commit inside the callback with flushSync:
import { flushSync } from "react-dom";
function selectTab(nextTab) {
if (!document.startViewTransition) return setTab(nextTab);
document.startViewTransition(() => {
flushSync(() => setTab(nextTab));
});
}React has also been developing a built-in <ViewTransition> component, and Next.js has exposed it behind an experimental flag. Both were still experimental in 2026, so check the current React and Next.js docs before depending on them in production. The flushSync pattern works today in any React version that has it.
Accessibility and Performance
Respect reduced motion
Large slides and zooms can trigger discomfort for people with vestibular disorders. Reduce them, but keep a gentle fade if it helps orientation:
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation-duration: 0.01ms !important;
}
}Keep transitions short
Most UI transitions feel right between 150ms and 350ms. Longer transitions make a site feel slower, even when the actual navigation is fast.
Mind the cost
- The update callback blocks rendering. Fetch data before calling
startViewTransition()when you can, rather than inside the callback. - Morphing very large elements or dozens of named elements at once can drop frames on low-end phones. Name only what needs to move.
- Render-blocking
<link rel="expect">delays first paint. Measure Core Web Vitals before and after. Our guide to improving INP covers how to measure responsiveness.
Screen readers are not affected by the visual animation, but focus still matters. After a same-document transition that replaces the main content, move focus to the new heading so keyboard and screen reader users know the view changed.
Why Didn't My View Transition Run?
- Duplicate names. Two visible elements share a
view-transition-name. The transition is skipped, andreadyrejects with an error in the console. - The page was hidden. Transitions started while the tab is in the background are skipped.
- Another transition started. Starting a new view transition skips the one in progress.
- Cross-document: one page didn't opt in, the navigation crossed origins, or the new page took too long to load.
- Back/forward cache. A page restored from the back/forward cache keeps any names you set from JavaScript. Clear them in
pageswaporpagereveal, or you will hit the duplicate-name problem. - React. The state update wasn't wrapped in
flushSync, so the new snapshot matched the old one.
Chrome DevTools' Animations panel captures view transitions, so you can slow them down and inspect each pseudo-element.
Key Takeaways
document.startViewTransition(update)animates any DOM change. Feature-detect and callupdatedirectly as the fallback.@view-transition { navigation: auto; }on both pages animates same-origin page loads with no JavaScript.- Customise with
::view-transition-old(),::view-transition-new()and::view-transition-group(). - Matching
view-transition-namevalues create shared-element morphs. Names must be unique at capture time. - Use types for direction-aware animations and
view-transition-classto style many elements. - In React, wrap state updates in
flushSync. Client-side routers need same-document transitions. - Honour
prefers-reduced-motionand keep transitions short.
Your next step: add the two-line @view-transition rule to a multi-page site you maintain, then give its header a view-transition-name so it stays fixed during navigation.
Frequently Asked Questions
What is the View Transitions API?
It is a browser API that animates between two states of a page, or between two pages. The browser snapshots the old state, applies your update, snapshots the new state and animates between them with CSS you can customise.
Do view transitions work on multi-page websites?
Yes. Add @view-transition { navigation: auto; } to the CSS of both pages and same-origin navigations will animate, with no JavaScript. This cross-document mode is supported in Chrome and Edge 126+ and Safari 18.2+.
Which browsers support the View Transitions API?
Same-document transitions work in Chrome and Edge 111+, Safari 18+ and Firefox 144+. Cross-document transitions work in Chrome and Edge 126+ and Safari 18.2+; check caniuse for Firefox. Unsupported browsers update the page without animation.
Why is my view transition being skipped?
The most common reason is two visible elements sharing the same view-transition-name. Transitions are also skipped when the page is hidden, when another transition starts, when a cross-document navigation crosses origins, or when the new page takes too long to load.
How do I use view transitions in React or Next.js?
Use same-document transitions, because client-side navigation does not load a new document. Call document.startViewTransition() and wrap the state update in flushSync so React commits the DOM change before the new snapshot is taken.
Does the View Transitions API hurt performance?
Not when used carefully. Keep update callbacks fast, name only the elements that need to morph, keep durations short, and measure before adding render-blocking <link rel="expect"> tags, which can delay first paint.
References and Further Reading
- View Transition API · MDN Web Docs
- Using the View Transition API · MDN Web Docs
- CSS View Transitions Module Level 1 · W3C
- Same-document view transitions for single-page applications · Chrome for Developers
- Cross-document view transitions for multi-page applications · Chrome for Developers
Related Articles
Continue your learning journey with these related topics