Early preview · Six skills are always free. Paid skills open soon.
Website animation · 2 min read

Add a page transition as a progressive enhancement

Feature-detect the View Transitions API, preserve ordinary updates, and remove motion when the user requests it.

Editorial illustration of a door opening into a second softly lit miniature room.

Treat a page or view transition as an optional enhancement around a working update. The user should reach the same content when the API is unavailable or reduced motion is active. Keep navigation, focus, and browser history correct before adding a visual transition.

Feature-detect rather than assume support

js example

function updateView(update) {
  const reduced = window.matchMedia(
    '(prefers-reduced-motion: reduce)'
  ).matches;
  if (reduced || !document.startViewTransition) {
    update();
    return;
  }
  return document.startViewTransition(update);
}

This browser-only example wraps a synchronous DOM update. Framework updates may need their own integration to ensure the callback commits the new view at the right time. Check the current MDN documentation and your framework’s supported approach rather than copying this fragment into routing code blindly.

Keep the fallback styles complete

css example

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

Normal layout and content must exist independently of the snapshots. Do not use an animation to reveal text that would otherwise stay hidden.

Separate visual continuity from navigation

A transition between two filters on one page has different history and focus needs from navigating to a new route. A visual snapshot does not update the document title, establish a canonical URL, or move focus appropriately. Handle those concerns through your actual application behavior.

CheckExpected result
Unsupported APIOrdinary update succeeds
Reduced motionImmediate content change
Back buttonPrevious state or route restored correctly
Keyboard useFocus remains understandable
Rapid updateLatest state wins

Test without the enhancement

Disable the API path and repeat the task. If the interaction fails, the transition has become a dependency. Fix that before refining the effect. Avoid promising universal browser behavior; support changes, and the feature should remain optional even when widely available.

References and further reading

The examples and templates above are original. These references support the definitions and documented behavior discussed in the guide.