view-transition-name identifies a rendered element for a view transition. During a single transition, a custom name must be unique among the participating elements. Duplicate names cause the transition's ready promise to reject and the transition animation to be skipped. CSS alone does not start a same-document transition; application code calls document.startViewTransition around the DOM update.
CSS view-transition-name: give one live element one transition identity
When to use it
A review queue expands one selected case into a detail panel. The application applies a named class only to that selected card and the corresponding detail element at the appropriate stages of the update. It removes the class from other cards, including virtualized items that may briefly coexist. Test rapid reselection, an interrupted update, a hidden element, and a queue that renders two copies of the same case during a filter change. Keep the case identifier visible in text; the animated movement is optional. If the API is absent, update the DOM directly. The name is a transition identity, not a database key, and it need not encode private case data. match-element can assign browser-generated identities in supported same-document transitions, but it does not solve every cross-document mapping problem.
.review-card.is-transition-source { view-transition-name: selected-case; }
.case-detail.is-transition-target { view-transition-name: selected-case; }
@media (prefers-reduced-motion: reduce) { ::view-transition-old(selected-case), ::view-transition-new(selected-case) { animation-duration: .01ms; } }Cost and verification
A view transition captures visual snapshots, so a large card with images or filters can increase memory and painting work. Measure the real screen before animating several elements. The old and new elements may exist at different moments, but duplicate matching names in the same captured state break the transition. Keep the ordinary DOM update independent of transition success; the API is an enhancement. Review focus placement after the detail view appears, since a moving snapshot has no interactive semantics. The CSS sample supplies the identity and a reduced-motion treatment, while the application owns lifecycle, errors, and focus.
Common Mistakes
- Do not assign one custom name to every card in a list.
- Do not expect view-transition-name to start a transition.
- Do not use a moving snapshot in place of focus management.
Connected lessons
- CSS Property Decisions
- CSS view-transition snapshots: animate presentation, then restore interaction
- CSS reduced motion: remove nonessential movement at the source
- CSS discrete transitions: keep a closing panel visible long enough to fade
- HTML custom elements: preserve useful text before upgrade
