View Transitions

React 19 can animate the change between any two renders. Wrap something in <ViewTransition>, change it inside a Transition, and React asks the browser to snapshot the old and new screens and animate from one to the other: a cross-fade by default, or anything CSS or the Web Animations API can do. Below are eight demos, each teaching a different part of the API: try it, see which animations ran, then read what's going on, step by step, next to the code that does it. Turn on slow motion to watch each one closely.

How a view transition works

  1. Something changes inside a Transition: a state update in startTransition, a value from useDeferredValue, or a <Suspense> boundary revealing its content. Ordinary updates don’t animate.
  2. React finds the <ViewTransition> boundaries it touches and gives each one’s first DOM element a view-transition-name, so the browser knows what to track.
  3. The browser takes a picture of those elements, React updates the DOM, and the browser takes a second picture.
  4. The browser animates from the old pictures to the new ones, in a layer of pseudo-elements over the page that you can style with CSS or drive from JavaScript.

The four kinds of animation

React picks one for each boundary, from what happened to it. Each one is a prop that takes a class name (enter="slide-in"), and the “Last transition” line under every demo shows which ran.

PropWhenBy default
enterThe boundary mounts, or its <Activity> is shown.Fades in.
exitThe boundary unmounts, or its <Activity> is hidden.Fades out.
updateSomething inside it changed, or it moved or resized.Its box morphs from the old size and place to the new, cross-fading.
shareA named boundary unmounts while another with the same name mounts.One morphs into the other.

What the browser draws, and what CSS can target

::view-transition                      a layer over the whole page
└─ ::view-transition-group(.cls)        moves and resizes (update, share)
   └─ ::view-transition-image-pair(.cls)
      ├─ ::view-transition-old(.cls)    the “before” picture (exit)
      └─ ::view-transition-new(.cls)    the “after”, live (enter)

.cls is the class you passed, so enter="slide-in" is styled with ::view-transition-new(.slide-in) { animation: … }. React’s full reference is in its docs.

Morph into a page

  • name
  • share
  • useDeferredValue
  • the URL

Try it Tap a card to open it, then go back with the button or your browser’s Back.

Last transitionnothing yet, give it a try

What's going on

The thumbnail and the big picture are two different elements in two different parts of the tree: one unmounts as the other mounts. On their own they’d just fade. Giving both the same name tells React they’re the same thing, so it pairs them up (a share) and the browser animates one box into the other: position, size and a cross-fade between the two pictures.

Everything else in the grid has no partner, so it leaves with a plain exit, and the page’s text arrives with an enter.

How it works

  1. The open card is kept in the URL (?open=gatsby). useDeferredValue hands back a copy that updates a moment later, as a Transition, and only Transitions animate. That’s why the browser’s Back button animates too.
  2. Each thumbnail’s picture is wrapped in a <ViewTransition> named after the card.
  3. The page wraps its big picture in a <ViewTransition> with the same name. When one unmounts and the other mounts in the same Transition, React pairs them.
  4. share="vt-morph" adds a View Transition Class. CSS uses it to time the group, the box that moves and resizes from the old spot to the new one.
The code (numbers match the steps)
1const open = useDeferredValue(search.open)

// In the grid
{GALLERY.map((g) => (
  <button key={g.id} onClick={() => onOpen(g.id)}>
2    <ViewTransition name={`vt-photo-${g.id}`} share="vt-morph">
      <img src={g.image} alt="" />
    </ViewTransition>
  </button>
))}

// On the page it opens
3<ViewTransition name={`vt-photo-${item.id}`} share="vt-morph">
  <img className="hero" src={item.image} alt={item.title} />
</ViewTransition>

/* vt.css */
4::view-transition-group(.vt-morph) {
  animation-duration: 450ms;
  animation-timing-function: cubic-bezier(0.2, 0.9, 0.1, 1);
}

Fly between lists

  • name
  • share
  • update
  • startTransition

Try it Press → on a card to move it along, or let Fry move everything at once.

To do 3

  • Knock the pen off the desk
  • Sit on the keyboard
  • Yell at 5 AM, for no reason

Doing 2

  • Ignore the new bed, sit in its box
  • Nap in the sunbeam

Done 1

  • Stare at the wall

Last transitionnothing yet, give it a try

What's going on

A card that changes column is removed from one <ul> and added to another. To React that’s a brand new element. A name of its own turns that unmount and mount into a share, so the browser flies the card across instead of fading it.

The cards it leaves behind didn’t change, they only moved up. React notices that their boxes moved and gives them an update, which slides them into place.

How it works

  1. Each card’s boundary is named after the card, so every name on the page is unique.
  2. Moving a card is an ordinary state update, wrapped in startTransition.
  3. Cards that only moved get update; update="vt-shift" sets their timing.
  4. CSS lifts the flying card: it tilts the image pair (the layer holding the old and new snapshots) while the group carries it across.
The code (numbers match the steps)
{items.map((c) => (
1  <ViewTransition key={c.id} name={`vt-chore-${c.id}`}
3    share="vt-fly" update="vt-shift">
    <li>{c.text}</li>
  </ViewTransition>
))}

const move = (id, by) =>
2  startTransition(() => setChores((all) => moveCard(all, id, by)))

/* vt.css */
::view-transition-group(.vt-fly) { z-index: 2; animation-duration: 520ms; }
4::view-transition-image-pair(.vt-fly) { animation: vt-lift 520ms both; }
@keyframes vt-lift {
  50% { transform: rotate(-3deg) scale(1.06); }
}

Reorder, add, remove

  • key
  • update
  • enter
  • exit

Try it Vote for a spot near the bottom until it climbs, add a spot, or take one off.

  1. 1The keyboard, mid-sentence7 votes
  2. 2The sunbeam by the window6 votes
  3. 3The clean laundry4 votes
  4. 4Mark's chair, the second he gets up3 votes
  5. 5The box the printer came in2 votes

Last transitionnothing yet, give it a try

What's going on

No names this time. Each row is a keyed <ViewTransition> sitting straight inside the list. When the order changes, React measures every row before and after; a row whose box moved gets an update and slides from the old place to the new one.

A new row is an enter and a removed one an exit, and their neighbours slide to make room.

How it works

  1. One <ViewTransition> per row, straight inside the <ol>, with a stable key.
  2. A vote re-sorts the array inside startTransition.
  3. Rows that moved get update: the browser slides each group from its old box to its new one.
  4. enter and exit classes run keyframes on just the new or just the old snapshot.
The code (numbers match the steps)
<ol>
  {ranked(spots).map((spot) => (
1    <ViewTransition key={spot.id}
      enter="vt-slide-in" exit="vt-slide-out" update="vt-shift">
      <li>{spot.name} ¡ {spot.votes} votes</li>
    </ViewTransition>
  ))}
</ol>

const vote = (id) =>
2  startTransition(() => setSpots((all) => addVote(all, id)))

/* vt.css */
3::view-transition-group(.vt-shift) { animation-duration: 380ms; }
4::view-transition-new(.vt-slide-in) { animation: vt-slide 320ms both; }
::view-transition-old(.vt-slide-out) { animation: vt-slide-away 240ms both; }

Slide the way you go

  • addTransitionType
  • <Activity>
  • enter
  • exit
  • share

Try it Switch tabs left and right. Pet Fry a few times, visit another tab, and come back.

0 pets

Pet him a few times, switch tabs, then come back.

Last transitionnothing yet, give it a try

What's going on

The same change (setTab) should slide left or right depending on which way you went. addTransitionType labels the Transition with that reason, and a boundary’s class props can take an object that picks a class per label.

The panels live in <Activity>, which hides a panel instead of unmounting it. Hiding counts as an exit and showing as an enter, but the state inside survives. The underline is one element that only the selected tab renders, always with the same name, so it’s a share and slides across.

How it works

  1. addTransitionType, called inside startTransition, tags this Transition tab-forward or tab-back.
  2. enter and exit take an object: a class per type, and default for anything else.
  3. <Activity mode="hidden"> keeps the panel and its state; hiding it runs exit, showing it runs enter.
  4. The underline is rendered in one tab at a time with the same name: a share.
The code (numbers match the steps)
const select = (next) =>
  startTransition(() => {
1    addTransitionType(next > tab ? 'tab-forward' : 'tab-back')
    setTab(next)
  })

3<Activity mode={i === tab ? 'visible' : 'hidden'}>
  <ViewTransition default="none"
2    enter={{ 'tab-forward': 'vt-tab-in-right', 'tab-back': 'vt-tab-in-left', default: 'none' }}
    exit={{ 'tab-forward': 'vt-tab-out-left', 'tab-back': 'vt-tab-out-right', default: 'none' }}>
    <div role="tabpanel">...</div>
  </ViewTransition>
</Activity>

{i === tab && (
4  <ViewTransition name="vt-tab-indicator" share="vt-indicator">
    <span className="indicator" />
  </ViewTransition>
)}

Reveal what Suspense waited for

  • <Suspense>
  • use()
  • update
  • enter
  • exit

Try it Play the next message in each mode. Drag “Takes” up to slow the tape down.

Where the boundary goes

Message 1 of 10Monday, 9:02 AM

From: A recruiter

Hi, calling about your resume. Love the experience. Less sure about the floppy disks. My assistant says you put one in the drive and the job comes up on screen? Netflix is the one in front.

Last transitionnothing yet, give it a try

What's going on

When a <Suspense> boundary swaps its fallback for the real content, React treats the reveal like a Transition, so it can animate even though nothing called startTransition at that moment.

Where the <ViewTransition> sits decides how. Around the boundary, the fallback and the message are the same box at two moments: an update that morphs its size and cross-fades. Inside it, each side has its own boundary: the fallback makes an exit and the message an enter.

How it works

  1. The click starts a slow request and stores its promise inside startTransition. A new key makes a fresh boundary, which shows its fallback.
  2. Message calls use(promise), which suspends until the promise resolves.
  3. Around: one boundary holds the fallback, then the message, so the swap is an update.
  4. Inside: a boundary on each side, so it’s an exit and an enter, animated separately.
The code (numbers match the steps)
const next = () => {
  const promise = fetchMessage(n + 1, delay)
1  startTransition(() => setRequest({ n: n + 1, promise }))
}

function Message({ promise }) {
2  const message = use(promise)
  return <MessageCard message={message} />
}

// Around: one boundary, so fallback → message is an "update"
3<ViewTransition update="vt-reveal" default="none">
  <div className="tape">
    <Suspense key={n} fallback={<Rewinding />}>
      <Message promise={promise} />
    </Suspense>
  </div>
</ViewTransition>

// Inside: a boundary on each side, so it's "exit" + "enter"
<Suspense key={n} fallback={
4  <ViewTransition enter="vt-rise-in" exit="vt-rise-out"><Rewinding /></ViewTransition>
}>
  <ViewTransition enter="vt-rise-in" exit="vt-rise-out">
    <Message promise={promise} />
  </ViewTransition>
</Suspense>

Filter as you type

  • useDeferredValue
  • enter
  • exit
  • update

Try it Type “toy”, then clear it. Or tap the chips.

24 of 24

  • cat
  • fish
  • mouse
  • yarn
  • box
  • sunbeam
  • feather
  • bird
  • butterfly
  • spider
  • plant
  • couch
  • laundry basket
  • desk lamp
  • keyboard
  • computer mouse
  • mug
  • pen
  • laser dot
  • ribbon
  • sock
  • moon
  • rain
  • dog

Last transitionnothing yet, give it a try

What's going on

The text box has to show every keystroke straight away; an animation per key would make typing lag. useDeferredValue gives you a second copy of the query that trails behind, and React renders that copy as a Transition. So the box stays instant while the grid animates.

Inside the grid it’s the same keyed list as before: stickers that drop out exit, ones that come back enter, and the rest slide over with an update.

How it works

  1. The input is driven by query, ordinary state updated on every keystroke.
  2. useDeferredValue(query) lags behind, and its re-render counts as a Transition.
  3. The grid filters on the deferred copy, so only the grid’s change animates.
  4. Keyed boundaries in the grid give each sticker its own enter, exit or update.
The code (numbers match the steps)
const [query, setQuery] = useState('')
1<input value={query} onChange={(e) => setQuery(e.target.value)} />

2const deferred = useDeferredValue(query)
3const shown = STICKERS.filter(matches(deferred))

<ul className="grid">
  {shown.map((st) => (
4    <ViewTransition key={st.name}
      enter="vt-pop-in" exit="vt-pop-out" update="vt-shift">
      <li>{st.emoji} {st.name}</li>
    </ViewTransition>
  ))}
</ul>

Bring your own animation

  • onUpdate
  • instance.group
  • Web Animations
  • linear()

Try it Tap squares to send Fry running. Turn the spring off to compare, or drag the sliders.

Settles in 1233 ms, as linear() with 75 stops

Last transitionnothing yet, give it a try

What's going on

CSS classes can only choose between keyframes you wrote ahead of time. The callbacks, onEnter, onExit, onUpdate and onShare, run as the animation starts and hand you the pseudo-elements, so JavaScript can take over.

Here the browser has already built Fry’s move (it knows his old and new boxes), and onUpdate just changes its timing to a spring simulated in JS.

How it works

  1. Moving Fry changes his grid cell inside a Transition, so his boundary gets an update.
  2. onUpdate runs once the animation exists. instance.group is this boundary’s ::view-transition-group.
  3. getAnimations() returns the browser’s move; updateTiming swaps its duration and easing and keeps its keyframes.
  4. The easing is the spring, sampled once a frame into a CSS linear() curve, which can go past 1 to overshoot.
The code (numbers match the steps)
1const go = (spot) => startTransition(() => setSpot(spot))

2<ViewTransition update="vt-spring" onUpdate={(instance) => {
  for (const a of instance.group.getAnimations()) {
3    a.effect.updateTiming({ duration: curve.duration, easing: curve.easing })
  }
}}>
  <div style={{ gridArea: area(spot) }}><PixelCat /></div>
</ViewTransition>

// spring.ts: simulate it, sample it once a frame, hand CSS the samples
while (!settled) {
  v += (stiffness * (1 - x) - damping * v) * dt
  x += v * dt
  points.push(x)
}
4const easing = `linear(${points.join(', ')})`

The whole page

  • addTransitionType
  • :active-view-transition-type()
  • clip-path

Try it Switch themes, here or at the top of the page.

Last transitionnothing yet, give it a try

What's going on

Most of this page keeps the root out of the snapshot, so only the demo that changed animates and everything else stays live. For the theme switch the whole window is captured instead, and the new look grows out of the button in a circle.

React also passes each Transition Type on to the browser, so CSS can pick out this one transition with :active-view-transition-type(theme).

How it works

  1. Before the Transition, the button’s position goes into custom properties on <html> (the pseudo-elements inherit from it), and the root gets a name so the whole window is snapshotted.
  2. addTransitionType('theme') labels the Transition.
  3. The switch is a boundary that only animates for theme. Some boundary has to animate, or React won’t start a view transition at all.
  4. In CSS, :active-view-transition-type(theme) keeps the old window still and reveals the new one through a growing clip-path circle.
  5. An effect takes the root’s name off again. Effects run after the transition finishes.
The code (numbers match the steps)
const pickTheme = (next, e) => {
1  root.style.setProperty('--vt-reveal-x', `${x}px`)
  root.style.setProperty('view-transition-name', 'root')
  startTransition(() => {
2    addTransitionType('theme')
    setTheme(next)
  })
}

3<ViewTransition default="none" update={{ theme: 'vt-picker', default: 'none' }}>
  <div role="group">...</div>
</ViewTransition>

/* vt.css */
4:root:active-view-transition-type(theme)::view-transition-old(root) { animation: none; }
:root:active-view-transition-type(theme)::view-transition-new(root) {
  animation: vt-reveal 650ms ease-in-out both;
}
@keyframes vt-reveal {
  from { clip-path: circle(0 at var(--vt-reveal-x) var(--vt-reveal-y)); }
  to { clip-path: circle(var(--vt-reveal-r) at var(--vt-reveal-x) var(--vt-reveal-y)); }
}

useEffect(() => {
5  root.style.removeProperty('view-transition-name')
}, [theme])