Sub topic 4
Understanding the default cross-fade
This chapter assumes you can call document.startViewTransition() and know the capture, update, animate lifecycle from the earlier chapters. You should also know what pseudo-elements are and how @keyframes works. Here you will see what the browser does when you write no transition CSS at all, and why it looks the way it does.
What you get with no CSS
Call document.startViewTransition(() => updateView()) on a page with no ::view-transition rules. The whole page cross-fades from the old state to the new one over 0.25 seconds.
You wrote no animation, so the browser's built-in (user-agent) stylesheet is supplying one. That stylesheet is ordinary CSS applied to the pseudo-element tree, so your own rules can override it. To change the default effectively, you need to know what it contains.
The root snapshot
When no element has a view-transition-name, the browser captures one thing: the root element, <html>, as the named transition root. That snapshot includes everything on the page. It also includes the root's background, which the browser propagates from html or body onto the canvas.
The tree for a page with only the root looks like this:
Each level has a job:
::view-transitionis an overlay that covers the viewport and sits above the page.::view-transition-group(root)animates the position and size of the snapshot. For the root, the old and new sizes usually match, so you see no movement.::view-transition-image-pair(root)wraps the two images and isolates them from the rest of the page.::view-transition-old(root)shows the old state as a static image.::view-transition-new(root)shows the new state as a live rendering of the updated page, so videos and CSS animations in it keep running.
The built-in rules
The exact text of the user-agent stylesheet is defined by the specification and can change slightly between browsers. This is a close paraphrase of the parts that matter:
:root::view-transition {
position: fixed;
inset: 0;
}
:root::view-transition-group(*) {
position: absolute;
top: 0;
left: 0;
animation-duration: 0.25s;
animation-fill-mode: both;
}
:root::view-transition-image-pair(*) {
position: absolute;
inset: 0;
animation-duration: inherit;
animation-fill-mode: inherit;
isolation: isolate;
}
:root::view-transition-old(*),
:root::view-transition-new(*) {
position: absolute;
inset-block-start: 0;
inline-size: 100%;
block-size: auto;
animation-duration: inherit;
animation-fill-mode: inherit;
mix-blend-mode: plus-lighter;
}
:root::view-transition-old(*) {
animation-name: -ua-view-transition-fade-out;
}
:root::view-transition-new(*) {
animation-name: -ua-view-transition-fade-in;
}The -ua- keyframes are internal. The fade-out goes from opacity 1 to 0, and the fade-in goes from 0 to 1. You cannot reference them by name, but writing your own @keyframes gives the same result.
Three details in these rules explain most of the default behavior.
Duration is set once and inherited
Only the group declares animation-duration: 0.25s. The image pair and the old and new images use inherit. So you can change the timing of the whole cross-fade with one rule:
::view-transition-group(root) {
animation-duration: 0.6s;
}If you instead set a duration on ::view-transition-old(root) alone, only the fade-out changes. The fade-in keeps its inherited 0.25 seconds, and the two images fall out of step.
Blending with plus-lighter
A plain cross-fade is where the old layer's opacity goes from 1 to 0 while the new layer's goes from 0 to 1. Halfway through, each layer is 50% opaque. Normal alpha compositing then lets the page background show through slightly, and you see a dip in brightness. The effect is worst on images and solid-color areas.
mix-blend-mode: plus-lighter adds the color values of the two layers instead of compositing them. At the midpoint, 50% of the old plus 50% of the new gives full brightness. The isolation: isolate on the image pair keeps this blending inside the pair, so it does not mix with the page behind the overlay.
The fill mode keeps the end state
animation-fill-mode: both holds the first keyframe before the animation starts and the last one after it ends. This prevents a one-frame flash of the unstyled new image at the start. It also keeps the new image fully visible until the browser removes the overlay.
A runnable demonstration
This page switches between two colored panels. It has no transition CSS, so what you see is the default.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Default cross-fade</title>
<style>
body { margin: 0; font: 24px system-ui; }
#panel { height: 100vh; display: grid; place-items: center; }
.a { background: #fde68a; }
.b { background: #93c5fd; }
</style>
</head>
<body>
<div id="panel" class="a">Click anywhere</div>
<script>
const panel = document.querySelector('#panel');
function toggle() {
panel.className = panel.className === 'a' ? 'b' : 'a';
panel.textContent = panel.className === 'a' ? 'Panel A' : 'Panel B';
}
document.addEventListener('click', () => {
if (!document.startViewTransition) {
toggle();
return;
}
document.startViewTransition(toggle);
});
</script>
</body>
</html>Now add the following rule to the stylesheet and click again. The fade slows to 2 seconds, which makes the tree easy to inspect in DevTools.
::view-transition-group(root) {
animation-duration: 2s;
}Common problems with the default
The default is simple, but it produces a few predictable surprises.
| Symptom | Cause | Fix |
|---|---|---|
| Clicks do nothing for a quarter second | The `::view-transition` overlay sits above the page and receives pointer events while it exists | Keep durations short, or set `pointer-events: none` on `:root::view-transition` if the page must stay interactive |
| A white or black flash at the start or end | The root has no opaque background, so the snapshot has a transparent area | Give `html` or `body` an explicit `background-color` |
| Sticky headers and sidebars also fade | They are part of the root snapshot, because nothing else has a name | Give them a `view-transition-name` so they are captured separately |
| A custom fade looks darker in the middle | You overrode `mix-blend-mode` or replaced the animation without keeping `plus-lighter` | Restore `mix-blend-mode: plus-lighter` on both images |
| A custom duration on the old or new image has no effect on the other | Only one pseudo-element was changed | Set the duration on `::view-transition-group(root)` so it inherits |
Why this matters for what comes next
Every customization in later chapters starts from these defaults. When you write animation: none on the old and new images, you remove the fade but keep the group, the overlay, and the blocking behavior. When you add a view-transition-name to an element, it gets its own group with the same 0.25-second default. Knowing which rules are inherited and which are set per element tells you where to put an override.
Exercise
You write ::view-transition-old(root) { animation-duration: 1s; } and leave everything else alone. What does the transition look like, and what single change would make both fades take 1 second?
Show answer
The old state fades out over 1 second. The new state still fades in over the inherited 0.25 seconds, because only the group sets a duration and the new image inherits it. The old image is gone by the time the new one has finished, but the new one is fully visible after 0.25 seconds, so the page shows the new state early and the overlay lingers. Setting ::view-transition-group(root) { animation-duration: 1s; } instead makes the image pair and both images inherit 1 second, so they fade together.
Exercise
Why does the default cross-fade use mix-blend-mode: plus-lighter on the old and new images?
Show answer
With ordinary alpha compositing, two layers at 50% opacity show the background through them, so the page dips in brightness at the midpoint. plus-lighter adds the two layers' color values, so 50% of the old plus 50% of the new gives full brightness. The image pair's isolation: isolate keeps that blending contained.