<ViewTransition> component to create smooth, directional animations between slides. Transitions are aware of navigation direction (forward/backward) and use CSS View Transition pseudo-elements for hardware-accelerated effects.
React 19 ViewTransitions
React 19 introduced the<ViewTransition> component and addTransitionType() API for declarative transitions. nextjs-slides wraps slide content with ViewTransition to enable coordinated enter/exit animations.
How It Works
SlideDeck wraps the current slide in a ViewTransition with directional animation types:
slide-deck.tsx
key={pathname}— Forces a new ViewTransition when the route changesdefault="none"— No animation by defaultenter— Animation types for the incoming slideexit— Animation types for the outgoing slide
ViewTransition captures the old and new DOM state, creating pseudo-elements (
:view-transition-old and :view-transition-new) that can be animated with CSS.Directional Transitions
When navigating,SlideDeck uses addTransitionType() to tag the transition:
slide-deck.tsx
Transition Types
TRANSITION_FORWARD('slide-forward') — Next slide (→ or Space)TRANSITION_BACK('slide-back') — Previous slide (←)
| Direction | Enter Animation | Exit Animation |
|---|---|---|
| Forward | slide-from-right | slide-to-left |
| Backward | slide-from-left | slide-to-right |
| Default | slide-from-right | slide-to-left |
CSS Animations
The CSS animations are defined innextjs-slides/styles.css using View Transition pseudo-elements:
styles.css
Pseudo-Elements
::view-transition-old(name)— The outgoing slide snapshot::view-transition-new(name)— The incoming slide snapshot
Exit Animation
The deck itself has an exit animation when navigating away (e.g. clicking the × button):slide-deck.tsx
deck-unveil animation creates a shrinking effect:
styles.css
startTransition
SlideDeck uses React’s useTransition to wrap navigation:
slide-deck.tsx
startTransition— Marks the navigation as a non-blocking transitionisPending— Tracks whether the transition is in progress
Transition Lifecycle
- User presses arrow key —
keydownlistener triggersgoTo() - Add transition type —
addTransitionType('slide-forward')oraddTransitionType('slide-back') - Start transition —
startTransition()wrapsrouter.push() - Capture old state — Browser snapshots the current slide
- Update route — Next.js renders the new slide
- Capture new state — Browser snapshots the new slide
- Animate — CSS animations run on
::view-transition-oldand::view-transition-new - Complete — Pseudo-elements are removed, new slide is live
Customizing Animations
Override the default animations by redefining the pseudo-element styles:globals.css
Change Duration
globals.css
Change Easing
globals.css
Import
nextjs-slides/styles.css in your global CSS to ensure the base animations are defined. Your overrides should come after.Performance
View Transitions use hardware-accelerated transforms and run on the GPU:transform: translateX()— GPU-acceleratedopacity— GPU-accelerated- No layout thrashing — Animations don’t trigger reflows
Browser Support
React 19 ViewTransitions require:- React 19 —
<ViewTransition>component - Modern browsers — Chrome 111+, Edge 111+, Safari 18+ (with polyfill)
Related
- SlideDeck Provider — How the provider orchestrates transitions
- Keyboard Navigation — How arrow keys trigger transitions
- Routing — URL changes that trigger ViewTransitions