FrontendView TransitionsCSSAstroNuxt

View Transitions API: native navigation animations in Astro, Nuxt and CSS

Pablo Alcalde García

Smooth transitions between screens made native apps feel more polished than the web. For years, replicating them required animation libraries and a lot of fragile code. The View Transitions API brings it to the browser: the browser itself captures the “before” and the “after” and animates between them with CSS.

Two ways to use it

  1. Same-document transitions (SPA): you change the DOM with JavaScript and wrap the change in document.startViewTransition().
  2. Cross-document transitions (multi-page sites): you enable a CSS rule and the browser animates the normal navigation between pages, no SPA needed.

The second is especially attractive: a traditional static site gets elegant transitions with zero JavaScript.

Same-document transition

function updateList(newHTML) {
  if (!document.startViewTransition) {
    container.innerHTML = newHTML; // no support: normal change
    return;
  }
  document.startViewTransition(() => {
    container.innerHTML = newHTML;
  });
}

By default it does a cross-fade. Always plan for the unsupported case: the functionality must keep working without animation.

Cross-page transition with plain CSS

@view-transition {
  navigation: auto;
}

With that rule on both the origin and destination pages (same origin), the browser animates the navigation. Support has been growing, but check the current status on caniuse and treat it as progressive enhancement.

Animating specific elements

Give an element a name and the browser “pairs” it between the two pages, animating position and size:

/* Thumbnail in the list */
.card-image {
  view-transition-name: article-hero;
}
/* The large image on the detail page */
.article-image {
  view-transition-name: article-hero;
}

Important rule: each view-transition-name must be unique on the page. In lists, generate it dynamically (style="view-transition-name: item-{{id}}").

And you can customise the animation with pseudo-elements:

::view-transition-old(root) { animation: 200ms ease-out both fade-out; }
::view-transition-new(root) { animation: 300ms ease-in both fade-in; }

@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in  { from { opacity: 0; } }

In Astro

Astro integrates view transitions with a component added to the layout’s <head>. In version 4 it is called ViewTransitions; in later versions it was renamed ClientRouter. Check the documentation for your version:

---
import { ViewTransitions } from 'astro:transitions'; // Astro 4
---
<head>
  <ViewTransitions />
</head>

With directives such as transition:name and transition:persist you can pair elements and keep the state of components (an audio player, a menu) across pages. Keep in mind this turns navigation into client-side navigation: scripts that run on page load must listen to the astro:page-load event so they re-run. If you are interested in Astro, see the complete Astro guide.

In Nuxt

Nuxt offers experimental View Transitions support through a configuration option:

// nuxt.config.ts
export default defineNuxtConfig({
  experimental: {
    viewTransition: true,
  },
});

And you can enable or adjust it per page with definePageMeta. Since it is experimental, check the documentation for your Nuxt version (what’s new in Nuxt 4).

Accessibility: don’t forget it

Animations can annoy or disorient. Respect the system preference:

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

Also, don’t use animation to convey essential information, and keep durations short (ideally under half a second).

Performance and SEO

  • Transitions shouldn’t delay navigation: keep them light.
  • Avoid animating huge or numerous elements.
  • They don’t change what crawlers see: the content is still normal HTML. Combine it with Speculation Rules for near-instant navigations and with Core Web Vitals under control.

When it is worth it

  • Sites with repetitive navigation (catalogues, blogs, portfolios) where polishing the experience pays off.
  • When you already have a solid performance base.

And when not: if it forces you to restructure a lot or your audience mostly uses browsers without support, the benefit is small.

Conclusion

The View Transitions API brings the web closer to app-like fluidity with very little code, and degrades gracefully where there is no support. Start with the CSS navigation rule, add names to one or two key elements and always respect prefers-reduced-motion.

If you want a fast website with a carefully crafted experience, ask me for a call.

Call me now