CSS View Transitions Generator
Generate the complete CSS and JavaScript for a View Transitions API animation — including view-transition-name assignment, ::view-transition-old() and ::view-transition-new() keyframes, and the required document.startViewTransition() call. Choose a transition type (fade, slide, scale, or custom) to get production-ready output.
How to use the CSS View Transitions Generator
1. Enter a transition name — this becomes the value of view-transition-name on the element you want to animate and is used in the ::view-transition-old(name) / ::view-transition-new(name) pseudo-element selectors. 2. Set the duration and easing. 3. Pick a type: Fade cross-fades old and new; Slide variants translate old/new in opposite directions; Scale scales from small to full; Custom outputs empty keyframe stubs you can fill. 4. Copy the output — it includes the CSS and a ready-to-use JS snippet. Add view-transition-name: [name] to your element, and call document.startViewTransition(() => updateDOM()) from JavaScript when the state changes.
The View Transitions API — what it is and how it works
The View Transitions API (shipped in Chrome 111, Safari 18, Firefox behind a flag as of 2024) makes smooth animated transitions between DOM states a first-class browser feature. When you call document.startViewTransition(callback), the browser captures a screenshot of the current state, runs your callback (which updates the DOM — e.g. routing to a new page or toggling a panel), then cross-fades the snapshot with the new state. The entire fade happens in CSS via the ::view-transition-group, ::view-transition-image-pair, ::view-transition-old, and ::view-transition-new pseudo-elements.
Individual elements can opt in with view-transition-name: heroImage. When a named element exists in both old and new states, the browser automatically interpolates its position, size, and appearance across the transition — the "shared-element" pattern previously requiring JavaScript animation libraries. No FLIP calculation, no getBoundingClientRect bookkeeping; the browser handles it. Custom keyframes on ::view-transition-old(name) and ::view-transition-new(name) override the default cross-fade for that element.
The API is also being extended to same-document navigation via @view-transition { navigation: auto; }, enabling SPA-style page transitions with no JavaScript at all (Chrome 126+). Feature-detect with if (!document.startViewTransition) return; — without the check the callback just runs synchronously in unsupported browsers.
Common use cases
- SPA page transitions — wrap your router's DOM update in startViewTransition() for automatic cross-fades between pages in React, Vue, or vanilla JS without a library.
- Shared hero images — give a thumbnail and its expanded view the same view-transition-name so the browser morphs the position and size with zero JS.
- List reordering — animate list items rearranging (e.g. sort, filter) by wrapping the DOM mutation in a view transition — the browser interpolates positions automatically.
- Theme toggle — cross-fade between light and dark themes when toggling the data-theme attribute inside startViewTransition().
- Modal / detail panels — scale or slide a card into a detail view using a shared view-transition-name so the card appears to expand in place.