A class photo on the teacher’s board: give four cards a view-transition-name, shuffle them through startViewTransition, and the cards move the way the…
Why it matters
Smooth transitions make a UI feel connected instead of jumpy. This used to take the FLIP technique and manual position math; now it is one wrapper and one CSS property. Used for reordering lists, opening details, and page changes (this site uses it too).
The key idea
The browser takes two pictures, then animates them
Common mistakes
Duplicate view-transition-name Every name must be unique on the page when the picture is taken. Twin names abort the transition (transition.ready rejects). Use a unique id per element, like card-${id}.
Forgetting flushSync in React The browser captures the new state after the callback finishes, while a plain setState is written by React later. Wrap it in flushSync(() => setState(...)) so the DOM has changed by then.
Not handling older browsers Check if (!document.startViewTransition) first; if it is missing, run the update directly. The page still works, just without animation.
Try it in this playground
Use unique names, press Acak The cards glide to their new places. See each group's Δx and Δy, read from the browser's animations.
Give two cards the same name, then Acak transition.ready rejects with the browser's error. The cards jump at once.
Switch to plain (no flushSync), then Acak When the callback finishes, the DOM is still old: React has not written it.
Drag the duration to 1500 ms or more The morph is a plain CSS animation on a pseudo-element, so it can be slowed down.