Animated page changes without blocking the main thread
The View Transitions API delivers native, GPU-accelerated transition animations between two page states, entirely without a JavaScript animation loop. Compared to classic transition libraries, main-thread load drops noticeably, and since cross-document view transitions arrived, the same principle now works for classic multi-page navigation too.
Inhaltsverzeichnis
- 1. What is the View Transitions API
- 2. How It Works, With a Code Example
- 3. Difference to JavaScript-Based Transition Libraries
- 4. Cross-Document View Transitions for Multi-Page Navigation
- 5. CSS Customization With view-transition-name
- 6. Performance Measurement and Compositor Behavior
- 7. Browser Support and a Fallback Strategy
- 8. Practical Examples and the API's Limits
- 9. Summary
- 10. Zusammenfassung
- 11. FAQ
1. What is the View Transitions API
The View Transitions API lets developers present a change in the visible page state as an animated transition without writing custom animation logic in JavaScript. The browser automatically takes a snapshot of the old state, applies the DOM change, and then takes a snapshot of the new state, running a default crossfade animation between the two.
This flow is triggered through the document.startViewTransition() method, which takes a callback function containing the actual DOM change. Everything else, meaning capturing the snapshots, generating the pseudo-elements, and playing the animation, is handled by the browser itself, reducing the implementation effort for simple transitions to just a few lines of code.
2. How It Works, With a Code Example
Technically, for the duration of the transition the browser builds a tree of pseudo-elements headed by ::view-transition, with ::view-transition-group underneath, and finally ::view-transition-old and ::view-transition-new for the old and new state respectively. These pseudo-elements are essentially static images that can be animated with CSS, which means every transition ultimately boils down to an ordinary CSS animation.
That's exactly where the key performance advantage lies: because the animation runs via transform and opacity on two static image layers, it can be handed off entirely to the GPU compositor thread without JavaScript needing to intervene on a per-frame basis. The example below shows a minimal implementation for swapping a detail section.
function updateContent(newHtml) {
if (!document.startViewTransition) {
// Fallback for non-supporting browsers
document.querySelector('#content').innerHTML = newHtml;
return;
}
document.startViewTransition(() => {
document.querySelector('#content').innerHTML = newHtml;
});
}
3. Difference to JavaScript-Based Transition Libraries
Classic animation libraries such as Framer Motion or GSAP typically drive transitions through a requestAnimationFrame loop, computing intermediate values and updating style properties on every single frame. Even when these libraries stick to pure transform and opacity changes, the computation logic itself still runs on the main thread, which can cause jank whenever other scripts are running at the same time.
The View Transitions API sidesteps this problem because the default animation is described entirely declaratively via CSS, and the browser can hand it off directly to the compositor without involving the main thread on a per-frame basis. Only the actual DOM change inside the callback runs on the main thread, the animation itself doesn't, which makes a noticeable difference on resource-heavy pages with many scripts running concurrently.
4. Cross-Document View Transitions for Multi-Page Navigation
While the first version of the API only worked within a single page, meaning in the context of single-page applications, cross-document view transitions extend the same principle to classic multi-page navigation between two separate HTML documents of the same origin. This is enabled purely declaratively via the CSS rule @view-transition { navigation: auto; }, which must be included on both pages involved.
The browser automatically takes a snapshot of the current page right before it's left, loads the destination page normally, and after it's built takes a second snapshot for the transition animation. The decisive advantage over JavaScript-based solutions is that no client-side routing is required at all, meaning classic server-rendered websites can benefit from animated transitions without an SPA architecture.
5. CSS Customization With view-transition-name
The CSS property view-transition-name lets individual elements be named separately, so they get their own animation during the transition instead of being part of the global crossfade. This matters especially for so-called shared element transitions, where, for example, a product image on a listing page morphs seamlessly into the larger image on the detail page, while the rest of the page animates separately.
These named transitions can additionally be targeted through the generated pseudo-elements such as ::view-transition-old(product-image) and ::view-transition-new(product-image) with custom keyframes, durations, and easing functions. This gives a high degree of design control without needing JavaScript, improving both maintainability and performance.
6. Performance Measurement and Compositor Behavior
Anyone wanting to measure the impact of view transitions on their own page should use the Performance tab in Chrome DevTools and specifically watch compositor thread activity during the transition. Ideally, the recording shows almost no main-thread activity outside the actual DOM change, while the animation phase shows up almost exclusively as GPU activity.
A common mistake is triggering expensive layout calculations or synchronous reflows inside the startViewTransition callback, which slows down the actual DOM update and thereby delays the start of the animation. Since the callback must complete synchronously before the new snapshot is taken, it pays off to keep the work inside it as lean as possible.
7. Browser Support and a Fallback Strategy
The basic View Transitions API for single-page contexts is supported by Chrome and Edge, while Safari has meanwhile added support as well, and Firefox is still catching up. Cross-document view transitions remain limited to Chromium browsers for now, which makes a clean fallback for non-supporting browsers essential.
The fallback is usually simple: if document.startViewTransition isn't recognized, just apply the DOM change directly without any animation, as shown in the code example above. For cross-document transitions, lack of support simply means the navigation happens without a transition effect, which is not a functional drawback at all, just the animated extra flourish is missing.
8. Practical Examples and the API's Limits
In practice, the View Transitions API works great for filter transitions on product listings, expanding detail views, or switching between tabs, cases that previously required manually managed CSS transition classes. Even on classic multi-page stores, moving from a category page to a product page can be noticeably enhanced with cross-document transitions, without having to restructure the architecture into a single-page application.
Limits show up with very complex, individually choreographed animations involving many elements timed differently at once, where a dedicated animation library still offers more control. Large, heavily changing layout areas can also briefly cause memory and rendering overhead while snapshots are being taken, so testing on lower-powered devices before shipping is recommended.
9. Summary
The View Transitions API shifts the actual animation work from the main thread to the compositor by describing transitions as a pure CSS animation between two snapshots, instead of computing them through JavaScript frame loops. For developers that means less code, for users it means smoother transitions, especially on devices with limited CPU power.
With cross-document view transitions, this principle becomes usable for classic, server-rendered multi-page websites for the first time, making it one of the more interesting new performance tools for traditional web shops. Anyone planning ahead today should consistently account for the fallback on non-supporting browsers and roll out the API gradually for individual page transitions.
| Criterion | JS Animation Library | View Transitions API |
|---|---|---|
| Execution location | Main thread (requestAnimationFrame) | GPU compositor thread |
| Code footprint | Several lines per transition | One call to startViewTransition |
| Multi-page support | Only with client-side routing | Native via cross-document transitions |
| Customizability | Very high, full JS control | High, via per-element CSS keyframes |
Mironsoft
Web performance, Core Web Vitals, and load time optimization
Load times that don't make users bounce before the page is even visible?
We review existing websites for slow Core Web Vitals, bloated JavaScript bundles, and unnecessary render blockers, then build a performance foundation that stays measurable instead of just looking good once.
Performance Audit
Systematically measuring and fixing Core Web Vitals, load waterfall, and render blockers.
Bundle Optimization
Specifically reducing JavaScript and CSS bundle size and improving code splitting.
Monitoring Setup
Establishing continuous performance monitoring instead of a one-time snapshot.
10. Zusammenfassung
View Transitions API
Technique
Snapshot-based CSS animation between two states
Effect
Smooth transitions without main-thread load
New
Cross-document transitions for multi-page navigation
Support
Chrome, Edge, Safari, Firefox in progress