property

View transition name — CSS reference

Assigns a capture identity to a rendered element. Corresponding old and new elements with the same unique name can animate together. Duplicate names in one captured state prevent that transition from running. The default none does not independently capture the element.

Formal Syntax & Structure

css syntaxcss
view-transition-name: card;

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>view-transition-name</title><style>body{margin:12px;font:16px system-ui}#card{width:120px;padding:12px;background:#e2e8f0;color:#172033;view-transition-name:card}#card.changed{width:220px;background:#bfdbfe}::view-transition-group(*){animation-duration:.5s}@media(prefers-reduced-motion:reduce){::view-transition-group(*),::view-transition-old(*),::view-transition-new(*){animation-duration:0s!important}}#card{view-transition-name:card}</style><body><button id="run" type="button">Change card</button><p id="card">Old state</p><output id="status" aria-live="polite"></output><script>const card=document.getElementById('card');const root=document.documentElement;const feedback=document.getElementById('status');function update(){card.classList.toggle('changed');card.textContent=card.classList.contains('changed')?'New state':'Old state';}function start(types){if(!document.startViewTransition||matchMedia('(prefers-reduced-motion: reduce)').matches){update();return null;}return types?document.startViewTransition({update,types}):document.startViewTransition(update);}async function inspect(check,types){const t=start(types);if(!t)return false;try{await t.ready;return await check(t);}finally{t.skipTransition();await t.finished;}}const ps=(name,prop)=>getComputedStyle(root,name).getPropertyValue(prop);run.onclick=async()=>{const t=start();if(t){try{await t.finished;}catch(e){feedback.textContent='Update failed';return;}}feedback.textContent='Updated';};</script></body></html>
CSS Reference