Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The view-transition-name property

Reference for the CSS view-transition-name property: name an element so it morphs between states during a view transition, with a live example and uniqueness rules.

The view-transition-name property marks an element as a separate participant in a view transition. During a transition the browser takes a picture of the old state and the new state; an element with a name is captured on its own, and the browser animates it from its old position and size to its new one instead of cross-fading the whole page.

Naming the same element before and after a change is how you get a "shared element" effect, such as a thumbnail growing into a hero image.

CSS
.card {
  view-transition-name: product-card;
}

Try it

A named box that moves

The card changes position, width and color. Because it has a name, the browser animates it smoothly (position and size) while the rest of the page cross-fades.

Syntax

CSS
view-transition-name: none | <custom-ident>
  • Initial value: none
  • Applies to: all elements
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
none The element is not captured separately. It is part of the root snapshot.
<custom-ident> A name for the element. It must not be none. The name is used in selectors like ::view-transition-group(card).

Newer specifications add keywords such as auto and match-element that name elements automatically. Support is still limited, so check a compatibility table before using them.

Usage notes

  • Names must be unique at the moment of the transition. If two rendered elements share a name, the transition is skipped. For lists, generate a name per item, for example with an inline style: style="view-transition-name: item-42".
  • Same name in old and new state. The browser pairs elements by name. If the element exists only in the new state, it fades in, and if only in the old one, it fades out.
  • Side effects. A named element gets its own stacking context and paint containment while the transition runs, so overflow and z-index can behave differently.
  • Style the transition. The pseudo-elements ::view-transition-group(), ::view-transition-image-pair(), ::view-transition-old() and ::view-transition-new() use the name. See ::view-transition.
  • Start the transition from script. For same-document changes, call document.startViewTransition(). Multi-page apps opt in with @view-transition.
  • Group with a class. view-transition-class lets you style several named elements at once.
  • Reduced motion. Disable or shorten the animation when prefers-reduced-motion: reduce matches.
  • Keep names off most elements. Naming everything makes each transition more expensive and may slow the page.

Browser support

Same-document view transitions are available in current versions of the major browsers, but they arrived in different years, and cross-document transitions are newer still. Check a compatibility table and always make the change work without the transition, as the example does.