pseudo-element

::view transition image pair() — CSS reference

Contains the old and new visual representations for a named group. Isolation lets their blending be confined to the pair.

Formal Syntax & Structure

css syntaxcss
::view-transition-image-pair(card) { isolation:isolate; }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>::view-transition-image-pair()</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}}::view-transition-image-pair(card){isolation:isolate}</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