View Transitions API: Smooth Page and State Transitions with CSS (and Minimal JS)
Animate state changes and page navigations with the View Transitions API: startViewTransition, naming, types, reduced motion and browser support.
document.startViewTransition(). In a multi-page site, one CSS rule, @view-transition { navigation: auto; }, animates same-origin navigations with no JavaScript. Give matching elements the same view-transition-name and they morph from one position to the other. Same-document transitions work in every major browser since October 2025; cross-document transitions work in Chromium and Safari and degrade to a normal navigation elsewhere.
Click a product thumbnail and the detail page appears instantly, with no sense of where it came from. Switch tabs and the content snaps. Reorder a list and items teleport to their new places. Animating between two DOM states used to mean measuring every element before and after the change, inverting the difference with transforms and playing it back, a technique known as FLIP, or cloning nodes into an overlay. Most teams skipped it.
The View Transitions API moves that work into the browser. It captures the current view, lets you update the DOM, captures the new view, and animates between them using a tree of pseudo-elements you can style with ordinary CSS animations. Same-document view transitions cover in-page state changes and single-page app routes. Cross-document view transitions cover navigations between real pages on the same origin.
My position: cross-document view transitions are the best low-effort upgrade available to content sites today, including WordPress blogs like this one. One CSS rule, no framework, and browsers without support lose nothing.
How a view transition works
Every view transition runs the same steps:
- The browser captures a snapshot of the current page and of every element with a
view-transition-name. - Rendering pauses while your update runs, either your callback or the navigation to the next page.
- The browser captures the new state as live content.
- It builds a pseudo-element tree over the page and animates from old to new.
- When the animations finish, the tree is removed and the real page shows through.
The pseudo-element tree looks like this, with one group per named element plus root for the rest of the page:
::view-transition
└─ ::view-transition-group(root)
└─ ::view-transition-image-pair(root)
├─ ::view-transition-old(root) (snapshot of the old view)
└─ ::view-transition-new(root) (live view of the new state)
By default the old view fades out and the new view fades in, and each group animates its size and position from the old element’s box to the new one. Everything is customizable with CSS.
Same-document transitions
Wrap the code that changes the DOM in document.startViewTransition(), with a fallback for browsers that do not support it:
function showTab(tabId) {
const update = () => {
document.querySelector("[aria-selected='true']")?.setAttribute("aria-selected", "false");
document.getElementById(tabId).setAttribute("aria-selected", "true");
renderPanel(tabId);
};
if (!document.startViewTransition) {
update(); // no animation, same result
return;
}
document.startViewTransition(update);
}
That is the whole integration. The callback can be async, but rendering stays paused until it resolves, so the page looks frozen while it waits. Fetch data first, then start the transition with an update that only touches the DOM.
Same-document view transitions became Baseline when Firefox 144 shipped them in October 2025, joining Chrome, Edge and Safari. The same release brought view-transition-class and the match-element naming value, both covered below.
Customizing the default animation
Style the pseudo-elements like any other element. This replaces the cross-fade on the whole page with a quick slide:
::view-transition-old(root) {
animation: 180ms ease-in both slide-out;
}
::view-transition-new(root) {
animation: 220ms ease-out both slide-in;
}
@keyframes slide-out { to { opacity: 0; translate: -24px 0; } }
@keyframes slide-in { from { opacity: 0; translate: 24px 0; } }
Keep page-level transitions short, roughly 150 to 300 milliseconds. While a transition runs, the pseudo-element overlay sits above the page, so clicks do not reach the real content. A long, pretty transition makes a site feel slower, not smoother.
Morphing shared elements with view-transition-name
Giving an element a view-transition-name pulls it out of the root snapshot into its own group. If an element in the old state and an element in the new state share a name, the browser morphs one into the other, animating position and size.
/* On the list page: the clicked card's image */
.product-card.is-active img { view-transition-name: product-hero; }
/* On the detail view: the large image */
.product-detail img { view-transition-name: product-hero; }
The thumbnail now grows into the hero image. Names must be unique among rendered elements at capture time. If two visible elements share a name, the transition is skipped and the update happens without animation. That is why the example only names the clicked card’s image, usually by setting a class or inline style just before starting the transition.
Many elements: match-element and view-transition-class
For lists that reorder, filter or sort, naming every item by hand is tedious. view-transition-name: match-element gives each element an automatic unique name based on its identity, and view-transition-class lets one rule style all of their groups:
.results li {
view-transition-name: match-element;
view-transition-class: result;
}
::view-transition-group(*.result) {
animation-duration: 250ms;
animation-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
Wrap the filter or sort in startViewTransition() and every item glides to its new position, items that leave fade out and new ones fade in. Without the API, this effect needed a FLIP animation library.
Cross-document transitions for multi-page sites
For ordinary page navigations, there is no JavaScript at all. Both the old and the new page must opt in:
@media (prefers-reduced-motion: no-preference) {
@view-transition {
navigation: auto;
}
}
Put this in the stylesheet every page loads. Same-origin navigations, such as clicking a link or using the back button, now cross-fade instead of flashing white. Named elements work across pages too: give the site header view-transition-name: site-header on every page and it stays visually fixed while the content changes underneath. Give a post’s thumbnail on the archive page and its featured image on the single page the same name, and the image morphs between them.
Chrome supports cross-document transitions since version 126 and Safari since 18.2. Firefox has same-document support but its cross-document support is still incomplete. Because the opt-in is a CSS rule, unsupported browsers simply navigate normally, so there is no reason to wait.
Two events help with dynamic names. pageswap fires on the old page just before it is replaced, and pagereveal fires on the new page before its first render. Use them to set a view-transition-name on the specific element that should morph, such as the card the user just clicked, and to clear it afterwards.
Transition types: different animations for different moves
Forward and back navigation often deserve different directions. View transition types let you tag a transition and style it conditionally:
document.startViewTransition({
update: () => goToStep(next),
types: [next > current ? "forward" : "backward"],
});
html:active-view-transition-type(forward) {
&::view-transition-new(root) { animation-name: slide-in-from-end; }
}
html:active-view-transition-type(backward) {
&::view-transition-new(root) { animation-name: slide-in-from-start; }
}
For cross-document transitions, set types in the at-rule, as in @view-transition { navigation: auto; types: slide; }, or in the pagereveal event. Types arrived in Firefox later than the core API, so check support and treat type-specific animations as optional. The nested CSS above uses the syntax from the native nesting guide.
Respect reduced motion
Large sliding and zooming movements can cause discomfort for people with vestibular disorders. The cross-document example above already opts in only when the user has no motion preference. For same-document transitions, either skip the API or neutralize the animations:
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation: none !important;
}
}
A short opacity cross-fade is usually acceptable even under reduced motion, so some teams keep a 100ms fade and remove only the movement. Either way, decide deliberately instead of shipping the same zoom to everyone.
Performance notes
- Snapshots are images. Naming hundreds of large elements means hundreds of textures. Name what matters visually, not everything.
- Rendering pauses during the update. Slow callbacks look like a frozen page. Do async work before the transition starts.
- The overlay blocks interaction. Keep durations short so users are not waiting for the animation to end.
- Cross-document transitions wait for the new page’s first render. A slow server response is still slow; the transition hides the white flash, not the latency.
Frequently Asked Questions
What is the View Transitions API?
The View Transitions API animates between two visual states of a page. The browser captures a snapshot of the current state, applies a DOM update or navigation, captures the new state, and animates between them using pseudo-elements that can be styled with CSS animations.
Do view transitions work in all browsers?
Same-document view transitions work in Chrome, Edge, Safari and Firefox since October 2025. Cross-document view transitions for multi-page sites work in Chrome and Edge since version 126 and Safari since 18.2, while Firefox support is still incomplete. Unsupported browsers simply update or navigate without animation.
How do I add page transitions to a multi-page website?
Add @view-transition { navigation: auto; } to the CSS loaded on every page, ideally inside a prefers-reduced-motion: no-preference media query. Same-origin navigations will then cross-fade, and elements with matching view-transition-name values on both pages will morph.
Why is my view transition not animating?
Common causes are two visible elements sharing the same view-transition-name, only one page opting in to cross-document transitions, a cross-origin navigation, or a browser without support. Check the console, which usually reports duplicate names.
Animate the change, not the page
View transitions turn state changes and navigations into continuous motion with almost no code. Add the cross-document opt-in to your site today, name the few elements that should morph, keep durations short and respect reduced motion. Animation is one source of rendering cost, and performance-safe CSS covers the others. Before that, pseudo-elements in practice shows how to add decorative details without extra markup.
Rule of thumb: if a transition is long enough to notice waiting for it, it is too long.
Originally posted on 10 September 2026 and post last modified on 10 September 2026