6.2 · Motion

Animate any change: view transitions

Wrap a DOM change and the browser animates from old to new.

document.startViewTransition(update) snapshots the page, runs your DOM change and animates from the old state to the new one. Elements with a view-transition-name move and resize smoothly, while everything else crossfades.

The animations are plain CSS on pseudo-elements like ::view-transition-group(). Across pages, @view-transition { navigation: auto; } does the same with no JavaScript. This site uses it.

Before
// FLIP by hand
const first = el.getBoundingClientRect()
update()
const last = el.getBoundingClientRect()
el.animate([{ transform: … }, { transform: 'none' }])
Now
document.startViewTransition(() => update())

li { view-transition-name: card-1; }

::view-transition-group(*) {
  animation-duration: 500ms;
}