CKTIS / CSS
::view-transition-old() — the old-state image
The ::view-transition-old() pseudo-element represents a static capture of the previous state during a view transition. It lets you animate the outgoing image independently of the new state, without styling the previous DOM element.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
::view-transition-old(<pt-name-and-class-selector>)
<pt-name-and-class-selector> = <pt-name-selector> <pt-class-selector>? | <pt-class-selector>
<pt-name-selector> = '*' | <custom-ident>
<pt-class-selector> = ['.' <custom-ident>]+::view-transition-old(card) selects the old-state capture associated with view-transition-name: card. It is a replaced element and a child of ::view-transition-image-pair(card), not the previous DOM node. Without an old state, this pseudo-element is absent; ::view-transition-new() represents the new state.
The argument * selects all such captures, while root is the document root element’s default transition name. Level 2 also accepts classes from view-transition-class, such as ::view-transition-old(.tile) and ::view-transition-old(card.tile). No whitespace is allowed within the name-and-class portion of the argument; these are not HTML classes.
The old image fades out by default. Your own animation can replace that animation; object-fit and object-position control the image as with other replaced elements. :only-child matches the old capture when there is no corresponding new capture.
The example updates a card through document.startViewTransition() and animates the old image’s opacity for 1200 ms. Without the API, it updates the content immediately. Local verification is required: API support does not guarantee support for every selector syntax or that an animation will run.
Examples
<!doctype html>
<meta charset="utf-8">
<title>Old snapshot</title>
<style>
html { view-transition-name: none; }
#card {
view-transition-name: card;
width: 12rem;
padding: 2rem;
background: navy;
color: white;
}
#card.changed { background: darkgreen; }
::view-transition-old(card) {
z-index: 1;
animation: leave 1200ms linear both;
}
::view-transition-new(card) { animation: none; }
@keyframes leave {
from { opacity: 1; }
to { opacity: 0; }
}
</style>
<p id="card">Before</p>
<button id="run" type="button">Run</button>
<script>
const card = document.querySelector('#card');
const button = document.querySelector('#run');
button.addEventListener('click', async () => {
button.disabled = true;
const update = () => {
card.classList.add('changed');
card.textContent = 'After';
};
if (typeof document.startViewTransition !== 'function') {
update();
return;
}
const transition = document.startViewTransition(update);
await transition.finished;
});
</script>Result
Initial: navy card displaying Before. After Run: darkgreen card displaying After; the button stays disabled. If the view transition runs, the old capture fades from full opacity to transparent over 1200 ms, revealing the new capture beneath it. Without the API, the update is immediate.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.