Sub topic 8
Support and graceful fallback
This chapter assumes you can already enable cross-document view transitions with @view-transition { navigation: auto; }. It also assumes you know the pseudo-element tree and have used the pageswap and pagereveal events. The goal here is to make sure the site works the same, minus the animation, in every browser that lacks the feature.
The fallback is a normal page load
A cross-document view transition is an enhancement on top of ordinary navigation. A browser that does not understand the feature does not break. It does what browsers did before the feature existed: it unloads the old page, loads the new one, and paints it.
Three things make this safe by default:
- A browser that does not recognize the
@view-transitionat-rule ignores it, like any other unknown at-rule. - Rules for
::view-transition-old(root)and similar pseudo-elements match nothing, so they have no effect. - The
pageswapandpagerevealevents never fire. A listener you registered simply never runs.
So the basic opt-in needs no extra fallback code:
@view-transition {
navigation: auto;
}Supporting browsers animate. Other browsers navigate instantly. Your job is to make sure nothing you wrote for the animated path leaves the instant path broken.
Know what support looks like
Support has arrived browser by browser. Chromium-based browsers (Chrome and Edge) shipped cross-document transitions in version 126. Safari followed in 18.2. Other engines may differ, and the table changes over time, so check a current compatibility table such as caniuse.com or MDN before you decide how much effort the fallback deserves.
Individual pieces also ship at different times. A browser can support @view-transition but lack a newer feature, for example:
| Feature | What happens if missing |
|---|---|
| `@view-transition` at-rule | No transition at all |
| `pageswap` / `pagereveal` events | Handlers never run, so dynamic names and types are never set |
| Transition types (`:active-view-transition-type()`) | Type-specific rules never match, so the default animation runs, or none if you only wrote typed rules |
| `rel="expect"` render blocking | The new page may render before the element is parsed |
Do not assume that "supports view transitions" means "supports everything in this tutorial". Design each piece so its absence degrades one step, not the whole experience.
What a user sees in each case
Every branch ends with the user on the correct new page. The only difference is how they get there.
Rules for writing fallback-safe CSS
The risk is not the transition rules. The risk is any change to your ordinary styles that only makes sense when a transition runs. Follow these rules.
Keep content visible without the transition
Do not hide content in the base stylesheet and rely on a transition animation to reveal it. If a page starts at opacity: 0 and only ::view-transition-new(root) brings it in, an unsupported browser shows a blank page.
/* Risky: unsupported browsers never run the reveal. */
main {
opacity: 0;
}
/* Safe: the page is visible by default. Only the snapshot is animated. */
::view-transition-new(root) {
animation: 300ms ease-out both fade-in;
}
@keyframes fade-in {
from {
opacity: 0;
}
}Animations on the ::view-transition-* pseudo-elements are the safe place for motion. They affect snapshots, not your live DOM, and only exist while a transition runs.
Remember that names have side effects
Setting view-transition-name on an element is not free in browsers that support it. A named element becomes a stacking context, even on navigations where no transition runs. That can change how z-index layering behaves around a sticky header or a modal. Test your layout in a supporting browser with and without the names in place. Browsers without support ignore the property, so the two paths can look different if you rely on the stacking side effect.
Use unique names too. If two elements on the same page share a name, the browser skips the transition for that navigation. This is a common reason a transition that works on one page silently does nothing on another.
Gate scripts, not just styles
Event listeners are harmless in unsupported browsers because the events never fire. The risk is code that touches APIs directly, outside of a handler. For example, window.navigation is not available everywhere. Use optional chaining, as in the pagereveal handler from the earlier chapter, or check first.
const supportsViewTransitions =
'CSSViewTransitionRule' in window && 'onpageswap' in window;
if (supportsViewTransitions) {
window.addEventListener('pageswap', (event) => {
if (!event.viewTransition || !event.activation) return;
const to = new URL(event.activation.entry.url);
event.viewTransition.types.add(
to.pathname.startsWith('/posts/') ? 'forward' : 'back'
);
});
}CSSViewTransitionRule is the interface for the @view-transition rule, so its presence tells you the opt-in will be understood. The onpageswap property checks for the event itself. Checking both avoids setting types in a browser that only supports part of the feature.
The event.viewTransition check inside the handler matters even in supporting browsers. It is null when the navigation is not getting a transition, for instance a cross-origin link. Always guard for it.
Detecting support in CSS
You can sometimes style differently depending on support. The @supports at-rule() syntax can test for an at-rule:
@supports at-rule(@view-transition) {
.site-header {
view-transition-name: site-header;
}
}Browser support for at-rule() inside @supports is itself limited, so a browser can support view transitions and still fail this test. In that case your names would never apply and the shared header would just crossfade with the rest of the page. If you use it, treat it as a refinement. Do not use it to guard anything essential. For most sites, setting the names unconditionally is simpler and nothing breaks where they are ignored.
Situations where a supporting browser still skips the transition
Fallback also covers cases inside supporting browsers. The transition is skipped, and a normal load happens, when:
- The navigation is cross-origin, or a redirect leaves the origin.
- One of the two pages has not opted in with
@view-transition. - The navigation is not one the browser allows to animate, such as certain reloads or navigations the user did not initiate through the page.
- The new page takes too long to become ready to render. Browsers set a time limit, so a slow response ends in a plain load.
- Two elements on a page share a
view-transition-name.
None of these show an error to the user. You only see them while debugging, which a later chapter covers. For now, remember that "no transition" is always a valid result, so test it as a first-class state of your site.
Testing the fallback
Build a short routine and run it before shipping:
- Open the site in a supporting browser and click through every main route. Confirm the transitions run.
- Turn on reduced motion in your operating system settings and repeat. Navigation should work with no movement.
- Open the site in a browser without support, or one with the feature disabled. Check that every page is readable and every layout is intact.
- Visit a page directly by URL, and also by clicking a link from another origin. Both are loads with no transition.
Step 3 catches the mistakes that matter most: hidden content, broken stacking order, and scripts that throw because an API is missing.
Summary
- Unsupported browsers ignore the at-rule and pseudo-element rules, and never fire the events, so they get a plain page load.
- Keep all motion inside
::view-transition-*rules and never depend on it to reveal content. - Treat
view-transition-nameas a change with a layout side effect, and keep names unique. - Guard direct API access, and check
event.viewTransitionin handlers. - A skipped transition in a supporting browser is normal, so test that state on purpose.
Exercise
A teammate sets main { opacity: 0; } in the base stylesheet and writes a ::view-transition-new(root) animation that fades from 0 to 1. Chrome looks fine, but users in a browser without support report a blank page. Explain the cause and give a fix.
Show answer
The base rule hides the content, and only the transition animation brings it back. A browser without support never creates the pseudo-elements, so the animation never runs and main stays at opacity 0. The fix is to remove opacity: 0 from main so the page is visible by default, and to keep only a from { opacity: 0; } keyframe on ::view-transition-new(root), so the fade applies only to the snapshot while a transition runs.
Exercise
Your pageswap handler calls event.viewTransition.types.add('forward') and works for internal links. After you add a link to an external site, the console shows a TypeError on that click. What is missing, and why can it happen even in a browser that supports the feature?
Show answer
The handler lacks a guard such as if (!event.viewTransition) return;. For a cross-origin navigation the browser does not create a view transition, so event.viewTransition is null and .types throws. The guard is needed in supporting browsers because a transition is created per navigation, not per page.