View Transitions: Animating Between Page States and Between Pages
Animating whole changes of state: startViewTransition() and its steps, the pseudo-element tree, view-transition-name, match-element and view-transition-class, custom animations, transition types, cross-document @view-transition, and reduced motion.
kvi5hnuCode Sprout team member8 min readOn this page
Transitions and animations work on one element's properties. A view transition animates a whole change of the page: a list being re-sorted, a thumbnail expanding into a detail view, or a navigation to another page. The browser takes a picture of the old state, lets you change the DOM in one step, and then animates from the old picture to the new state, with no need to keep both states in the DOM.
function sortList() {
if (!document.startViewTransition) { applySort(); return; } // no support: just update
document.startViewTransition(() => applySort());
}
With no other CSS, that crossfades the whole page from old to new.
How it works

document.startViewTransition(update):
- Captures the current state as images: the whole page as
root, plus each element with aview-transition-name. - Calls
update, which changes the DOM. Rendering is paused meanwhile, so users never see a half-updated page. It can be async. - Captures the new state.
- Builds a tree of pseudo-elements over the page and animates them, then removes them.
The pseudo-elements, on the root element:
| Pseudo-element | What it is | Default animation |
|---|---|---|
::view-transition | the overlay containing everything | none |
::view-transition-group(name) | one per name; sized and positioned like the element | moves and resizes from the old to the new box |
::view-transition-image-pair(name) | holds the two images; isolation: isolate | none |
::view-transition-old(name) | a static picture of the old state | fades out |
::view-transition-new(name) | the live new state | fades in |
Tested in Chrome, the group's default animation was 0.25s with ease. The old and new images used fade-out and fade-in animations with mix-blend-mode: plus-lighter, so a perfect crossfade doesn't dip in brightness in the middle.
The ViewTransition object returned has three promises, updateCallbackDone, ready (the pseudo-elements exist and animations are about to start) and finished, plus skipTransition(), which jumps to the end. Tested in Chrome, finished still resolved after skipTransition().
During the transition, the root matches :active-view-transition.

The red outline is ::view-transition-group(hero) moving and resizing. Inside it, the old and new images cross-fade, each keeping its own aspect ratio, which is why the old square picture hangs below the group in the 75% frame.
Naming elements: view-transition-name
By default, only the whole page crossfades. Giving an element a view-transition-name captures it separately, so it moves and resizes from its old position to its new one:
.site-header { view-transition-name: header; } /* stays put while the content changes */
.product-image { view-transition-name: hero; }
- The old and new elements with the same name are paired, even if they're different elements. A thumbnail named
heroon a list page and a large image namedheroon the detail state become one smooth movement. - Names must be unique among rendered elements when each state is captured. Tested in Chrome: with two elements named
same, the transition'sreadypromise rejected with anInvalidStateError, and the update happened without animation. - The default is
none. A named element is captured as one image together with its descendants, except descendants with their ownview-transition-name, which get their own groups.
For lists, giving each item its own name by hand is impractical. view-transition-name: match-element pairs elements by identity, so each item tracks itself:
.todo-list li { view-transition-name: match-element; view-transition-class: todo; }
view-transition-class lets one rule style many named groups: ::view-transition-group(*.todo) { animation-duration: 0.3s; }. Tested in Chrome, moving the first of three match-element list items to the end created a separate group for each item, each with the class's duration.
Customizing the animation
The pseudo-elements are styled like any other, with animation properties and @keyframes:
::view-transition-group(*) { animation-duration: 0.3s; animation-timing-function: cubic-bezier(0.2, 0, 0, 1); }
/* slide the main content instead of crossfading */
@keyframes slide-out { to { translate: -30% 0; opacity: 0; } }
@keyframes slide-in { from { translate: 30% 0; opacity: 0; } }
::view-transition-old(main) { animation: 0.3s ease-in both slide-out; }
::view-transition-new(main) { animation: 0.3s ease-out both slide-in; }
::view-transition-group(*)matches every group.- When an element's aspect ratio changes, the old and new images don't match the group: each is as wide as the group and keeps its own aspect ratio (
block-size: auto), so one overflows or falls short while the group resizes. Tested in Chrome, three quarters into a square thumbnail growing into a wide banner, the group was 236 × 113px, the old image 236 × 236px and the new one 236 × 100px.object-fiton::view-transition-old()and::view-transition-new()changes that, as for images, since they're replaced elements;height: 100%plusobject-fit: coveris common. - An element that only exists in the old or new state gets only an
-oldor-newimage, so it just fades out or in. animation: noneon a pseudo-element turns that part off.
Transition types
Different changes need different animations: forward and back, or opening and closing. Types label a transition, and :active-view-transition-type() selects them:
document.startViewTransition({ update: () => goToStep(n + 1), types: ['forward'] });
html:active-view-transition-type(forward) {
&::view-transition-old(main) { animation-name: slide-out; }
&::view-transition-new(main) { animation-name: slide-in; }
}
html:active-view-transition-type(back) { /* the reverse */ }
Tested in Chrome: during a transition started with the type forward, the root matched :active-view-transition-type(forward), and a rule using it changed the old image's animation duration to 2s.
Between pages: @view-transition
View transitions can also run on navigations between pages of the same origin, with no JavaScript. Both pages opt in:
@view-transition { navigation: auto; }
Elements with the same view-transition-name on both pages animate between them, and the rest crossfades. The pageswap event on the old page and pagereveal on the new one give access to the ViewTransition object, for example to set types based on the URLs.
Cross-document view transitions work in Chrome 126 and Safari 18.2; Firefox has them in preview. In other browsers, navigation simply happens as usual. They only run for same-origin navigations, and the new page should render quickly, since the browser waits for it.
Scoped and nested transitions
- Element-scoped view transitions,
element.startViewTransition(), run inside one element instead of the whole document, so several can run at once and the rest of the page stays interactive. Chrome 147 only. - Nested groups, with
view-transition-group: containornearest, keep a child's group inside its parent's group, so it's clipped by it and moves with it. Chrome 140 only.
Practicalities
- During a transition, the
::view-transitionoverlay covers the page, so clicks don't reach the page until it finishes. Keep transitions short. - Everything in the old state is a static picture: videos pause and hovering does nothing until the end.
- Reduced motion: crossfades are mild, but turn off movement for users who ask:
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
- View transitions are a progressive enhancement: always perform the update when
startViewTransitionis missing.
body { font: 0.85rem system-ui, sans-serif; margin: 1rem; }
.bar { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
button { font: inherit; padding: 0.3rem 0.7rem; }
.note { color: #555; }
.tiles { list-style: none; padding: 0; margin: 0.8rem 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.tiles.list { grid-template-columns: 1fr; }
.tiles li {
display: grid; place-items: center; block-size: 3.5rem; border-radius: 8px;
color: white; font: 800 1.2rem system-ui, sans-serif; background: var(--c);
view-transition-name: match-element; /* each tile animates to its new place */
view-transition-class: tile;
}
.tiles.list li { block-size: 2rem; place-items: center start; padding-inline: 0.8rem; }
::view-transition-group(*.tile) { animation-duration: 0.45s; animation-timing-function: cubic-bezier(0.2, 0, 0, 1); }
::view-transition-old(*.tile), ::view-transition-new(*.tile) { height: 100%; object-fit: cover; }
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
Shuffle moves each tile to its new place, although the DOM was simply reordered in one step: match-element gives every tile its own group. Toggle layout animates the tiles' size and position between a grid and a list, with object-fit: cover keeping the stretched images from distorting.
What's current
- Same-document view transitions,
view-transition-name,view-transition-class,match-element,:active-view-transitionand types: all browsers, since Firefox 144 (types: Firefox 147). - Cross-document
@view-transition: Chrome 126, Safari 18.2; Firefox in preview. - Element-scoped transitions (Chrome 147) and nested groups (Chrome 140): Chromium only.
Common questions
Why doesn't my view transition animate?
Two rendered elements may share a view-transition-name; the transition is then skipped. Check the console, and the ready promise's rejection.
Why does my element stretch during the transition?
Its aspect ratio changes. Set height: 100% and object-fit on its ::view-transition-old() and ::view-transition-new().
How do I animate between pages?
Add @view-transition { navigation: auto; } to both pages, which must be same-origin.
Do I still need FLIP (article 111)? Rarely: view transitions do the measuring and inverting for you.
Summary
document.startViewTransition(update)captures the old state, runs the update, captures the new state and animates between them.- The animation uses pseudo-elements: a group per name, containing an old picture and the live new view.
view-transition-namemakes an element move and resize separately; names must be unique;match-elementandview-transition-classscale to lists.- Customize with animations on the pseudo-elements, and label transitions with types.
@view-transition { navigation: auto }animates same-origin navigations; respect reduced motion and always fall back.
Practice questions
Write JavaScript that toggles a .compact class on a list with a view transition, working in browsers without support too.
Answer
const toggle = () => list.classList.toggle('compact');
document.startViewTransition ? document.startViewTransition(toggle) : toggle();
A card should expand into a detail panel smoothly. What CSS makes the browser treat them as the same thing?
Answer
Give both the same view-transition-name, with only one of them rendered at a time:
.card.selected, .detail { view-transition-name: product; }
The group then animates from the card's box to the panel's box.
Why does this transition never animate?
.product-card { view-transition-name: card; }
Answer
Every product card has the same name. Names must be unique among rendered elements, so the transition is skipped. Use view-transition-name: match-element, or unique names per card.
Write CSS that makes all view transitions in a site last 0.4s, and turns them off for reduced motion.
Answer
::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation-duration: 0.4s; }
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
Previous: Scroll-Driven Animations: scroll(), view() and Animation Ranges
Next: Scroll Snap and CSS Carousels: scroll-snap-type, ::scroll-button and ::scroll-marker

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.