Skip to content

Adding View Transitions to a Multi-Page Astro Site

The View Transitions API gives multi-page apps SPA-like page animations with a few lines of CSS, no client-side router or JavaScript framework required.

· · 7 min read

Updated: November 27, 2026

CSS with an @view-transition rule for navigation and animations on the old and new root snapshots

Quick Take

The cross-document View Transitions API animates full page navigations in a multi-page app using one `@view-transition { navigation: auto; }` CSS rule, no JavaScript router required. The browser captures a screenshot of the old and new page and cross-fades or animates between them. Tag elements with `view-transition-name` for shared-element transitions, like a hero image morphing between two pages instead of everything cross-fading at once, and the whole thing degrades to a normal navigation in unsupported browsers.

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.

Share this Post on X Bluesky

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.

Share this Post on X Bluesky

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.

Share this Post on X Bluesky

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.

  1. 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.
  2. Add the single @view-transition { navigation: auto; } rule to a global stylesheet loaded on every page.
  3. Tag any element that should persist visually across the navigation, like a hero image or page title, with a matching view-transition-name on both pages.
TaskBeforeWith cross-document View Transitions
Smooth page-to-page fadeClient-side router + JS-driven fadeOne @view-transition CSS rule
Shared hero image between pagesSPA framework animation libraryview-transition-name on both pages
Fallback for unsupported browsersManual feature detectionNone needed, unsupported browsers just navigate normally

Frequently Asked Questions

Does the View Transitions API require a JavaScript framework?
No. The cross-document version of the API, the one that animates full page navigations in a multi-page app, works with plain HTML and CSS, you opt in with a single @view-transition rule and the browser handles capturing the before/after screenshots and animating between them. A JavaScript-driven version also exists for single-page apps that swap DOM content without a full navigation, but MPAs don't need it.
What happens in browsers that don't support the View Transitions API?
Nothing breaks. The API is progressive enhancement by design, unsupported browsers simply navigate normally with no transition animation, the same instant page swap they'd get anyway. There's no polyfill needed and no fallback code required, you just don't get the animation in that browser.
Can I animate individual elements differently during a page transition?
Yes, using view-transition-name. Any element you tag with a unique view-transition-name value gets its own transition, tracked across the navigation, which is how a shared hero image or title can appear to smoothly move and resize between two pages instead of just cross-fading with everything else.