---
name: page-transitions
description: Use when animating between pages, routes, tabs or views, including shared-element transitions with the View Transitions API or layout animations.
---

# Page and view transitions

Transitions should show how screens relate: what moved, what replaced what, and where the user is now.

## Pick the right pattern

| Relationship | Transition |
| --- | --- |
| Drilling into an item (list to detail) | Shared element: the card grows into the page |
| Moving between sibling tabs | Slide 8-24px in the direction of the tab plus fade |
| Opening a temporary layer | Sheet or dialog over the page; the page stays put |
| Unrelated pages | Quick cross-fade, 180-250ms |

## View Transitions API (web)

```js
if (!document.startViewTransition) update();
else document.startViewTransition(() => update());
```

```css
.card-image { view-transition-name: hero; }
::view-transition-old(root), ::view-transition-new(root) {
  animation-duration: 280ms;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}
```

- Give each shared element a unique `view-transition-name` (only one element per name on the page).
- In Next.js App Router, start the transition before `router.push`, or use a transition-aware link helper.

## Layout animations (React)

Use Framer Motion `layoutId` for shared elements and `AnimatePresence` for enter and exit:

```tsx
<motion.img layoutId={`photo-${id}`} />
```

## Rules

- Keep the old page visible until the new one is ready; never flash an empty screen.
- Animate the content, not the whole viewport, when only part of the page changes.
- Back navigation reverses the forward animation.
- Restore scroll position on back.
- Reduced motion: replace movement with a short cross-fade.
