The View Transitions API is a browser feature that captures before-and-after snapshots of a page and animates between them, so a plain multi-page site can get SPA-like page transitions without shipping a client-side router. Most "smooth page transition" tutorials assume a single-page app with a client-side router intercepting navigation. A plain multi-page Astro build, full page loads and no router, looks like it can't have transitions at all. It can: the cross-document version of the API is built for exactly this case.
The one rule that turns it on
/* global.css, loaded on every page */
@view-transition {
navigation: auto;
}
That's the entire opt-in. With this rule present, every same-origin navigation on the site gets a default cross-fade transition between the old and new page, no other code required. Browsers that don't support the API ignore the unknown at-rule and navigate normally, so there's no fallback branch to write.
Cross-document view transition is the mode of the View Transitions API that fires on a full page navigation between two documents, as opposed to the same-document mode used by single-page apps to animate DOM swaps without a reload. According to Chrome's cross-document guide, support landed in Chrome 126 and has since shipped in every Chromium-based browser, Safari added it in 18.2 in December 2024, while release Firefox (161 in late November 2026) still treats the at-rule as an unknown token and skips it silently; MDN's compatibility data lists support from Firefox 162. The opt-in is the same three lines of CSS on any site, and the fallback for unsupported browsers requires zero extra code because an ignored at-rule just means a plain navigation happens, which is exactly what would have happened anyway. That combination, one rule, automatic feature detection, no polyfill, is why adopting it is far less work than any client-side router migration.
Customizing the default cross-fade
The default transition is a plain cross-fade, which is already an improvement over an instant page swap, but real design systems usually want something more specific:
::view-transition-old(root) {
animation: 200ms ease-out both fade-out;
}
::view-transition-new(root) {
animation: 200ms ease-in both fade-in;
}
@keyframes fade-out {
to { opacity: 0; }
}
@keyframes fade-in {
from { opacity: 0; }
}
::view-transition-old(root) and ::view-transition-new(root) are browser-generated pseudo-elements representing screenshots of the outgoing and incoming page. You're animating two static images, not the live DOM, which is why this stays fast even on a page with a lot of content, the browser isn't re-rendering anything during the animation. Per the spec, the browser builds a full pseudo-element tree, ::view-transition, ::view-transition-group, ::view-transition-image-pair, and the old/new pair, and any of those four layers can be targeted with custom CSS if two hundred milliseconds of fade isn't the effect you want.
A multi-page site with zero client-side JavaScript can get the same shared-element page transitions people assume require a single-page app and a router.
Shared-element transitions
The more striking effect is a single element, a hero image, a page title, appearing to smoothly move and resize between two pages instead of just fading. That needs a matching view-transition-name on both pages:
/* On the article list page: one name per card, never one shared class rule */
.article-card .thumbnail {
view-transition-name: var(--vt-name);
}
/* On the individual article page */
.article-hero-image {
view-transition-name: article-hero;
}
<!-- article-list.html -->
<a href="/blog/my-post/" class="article-card">
<img class="thumbnail" style="--vt-name: article-hero" src="/thumb.webp" alt="..." />
</a>
<!-- article page -->
<img class="article-hero-image" src="/hero.webp" alt="..." />
When the user clicks from the list to the article, the browser sees both elements share the name article-hero and animates the thumbnail growing into the hero image's position and size, instead of cross-fading two unrelated images. The visual effect reads as one image moving, not two images swapping.
view-transition-name is a CSS property that assigns a unique identifier to an element so the browser can track it across a navigation and animate it as one continuous object instead of two independent screenshots. It must be unique per page at any given moment. Reusing the same name on two rendered elements on the same page is invalid, and the browser skips the whole view transition, not just those two elements. That's why the list page above sets the name per card through a custom property: a single .thumbnail { view-transition-name: article-hero; } rule would hand every thumbnail the same name and kill the transition. Cards without --vt-name resolve to none and stay out of it. In a template, give each card a slug-based value such as hero-my-post and use that same name on the matching article page. Tagging just the thumbnail and the corresponding hero image takes a few declarations of CSS and no JavaScript at all.
A shared view-transition-name on two elements across a navigation makes the browser animate them as one continuous object, a thumbnail growing into a hero image, instead of cross-fading two unrelated screenshots.
prefers-reduced-motion needs an explicit guard
Motion needs an opt-out for users who've asked for reduced motion at the OS level. The browser doesn't apply one for you. Chrome's view transitions guide treats the preference as something your own CSS handles, so the default cross-fade and any custom @keyframes keep running until you add a guard:
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation: none !important;
}
}
Without this, the cross-fade and any slide or scale animation you wrote keep running for users who've explicitly asked their OS to minimize motion, defeating the purpose of the setting. The (*) selectors matter once you use view-transition-name: a guard on root alone leaves the shared-element groups animating. Chrome for Developers also points out that a preference for reduced motion doesn't mean the user wants no motion, so a shorter, subtler fade is a fair alternative to none.
Scoping transitions to specific navigations
Not every navigation should transition the same way, or at all. The navigation CSS property inside @view-transition only has one meaningful value today (auto), but you can scope which pages participate by conditionally including the transition CSS, or by checking the navigation type in a small script if you need per-route control:
// Skip the transition for back/forward navigations
window.addEventListener('pagereveal', (event) => {
if (!event.viewTransition) {return;}
const navigationType = window.navigation?.activation?.navigationType;
if (navigationType === 'traverse') {
event.viewTransition.skipTransition();
}
});
skipTransition() cancels the animation for that specific navigation while leaving the CSS rule active for every other one, useful for navigations where an animated swap would look wrong, back and forward traversals in this example. Reloads never get a cross-document transition in the first place: Chrome's guide excludes them, along with navigations started from the address bar. The listener goes on window, where the event is dispatched, and window.navigation?. keeps the script from throwing in Safari 18.2, which has pagereveal but didn't get the Navigation API until 26.2. The pagereveal event fires on every navigation, including ones that never trigger a view transition, so the if (!event.viewTransition) return; guard at the top is not optional, skipping it throws on any browser where the transition was never created in the first place.
The pagereveal event fires on every navigation regardless of whether a view transition was created, so scripts that call skipTransition must guard on event.viewTransition first or they throw in unsupported browsers and on skipped navigations.
Compared with the old way
Before this API existed, getting a smooth page-to-page fade meant reaching for a client-side router, a framework-level animation library, or a hand-rolled JavaScript fetch-and-swap that replaced the DOM without a full reload. The cross-document version replaces all three approaches with a CSS-only opt-in that the browser handles natively, no bundle size added, no router state to manage, and no risk of breaking back-button behavior the way custom fetch-based navigation often does. The table below lines up the three most common transition needs against what each approach used to cost versus what it costs now.
- Check whether the site already ships a client-side router purely for transitions, if the only reason is animation, this API usually replaces it outright.
- Add the single
@view-transition { navigation: auto; }rule to a global stylesheet loaded on every page. - Tag any element that should persist visually across the navigation, like a hero image or page title, with a matching
view-transition-nameon both pages.
| Task | Before | With cross-document View Transitions |
|---|---|---|
| Smooth page-to-page fade | Client-side router + JS-driven fade | One @view-transition CSS rule |
| Shared hero image between pages | SPA framework animation library | view-transition-name on both pages |
| Fallback for unsupported browsers | Manual feature detection | None needed, unsupported browsers just navigate normally |