Back to APIs

View Transitions API

Rendering

Enables smooth, app-like visual transitions between different states of the DOM, including between entirely different documents (Multi-Page Apps).

Support75%
BaselineLimited
ImpactLow
Popularity🔥 45

When to Use

  • Creating seamless navigation between pages in an SPA.
  • Animating elements that change their position in the DOM.
  • Implementing dark/light mode toggle animations.

When NOT to Use

  • If you need support for older iOS devices (fallback gracefully).
  • For highly complex, physics-based canvas animations.

Code Examples

Good: Feature-detected transition

Safely falls back to instant DOM updates if the browser lacks support.

function toggleTheme() {
  if (!document.startViewTransition) {
    document.body.classList.toggle('dark');
    return;
  }
  document.startViewTransition(() => {
    document.body.classList.toggle('dark');
  });
}

Advantages

  • Massively simplifies the code needed for cross-fades and morphing.
  • Runs natively in the browser compositor, providing excellent 60fps performance.
  • Reduces the need for heavy JavaScript animation libraries (like Framer Motion).

Limitations

  • Currently limited support in older Safari and Firefox (though it degrades gracefully to instant updates).
  • Can cause accessibility issues if users have `prefers-reduced-motion` enabled and it is ignored.

Common Mistakes

  • Forgetting to assign unique `view-transition-name` CSS properties to multiple moving elements on the same page.
  • Not checking for `document.startViewTransition` support and throwing an error.

References