On this page
Page transitions used to be the hardest animation in the Next.js App Router: the old page is gone the moment the new one renders, so there's nothing left to animate out. React's `<ViewTransition>` component fixes that by handing the change to the browser's View Transitions API, which snapshots the old page and animates to the new one. It works in the App Router with no configuration, and pages still work normally in browsers that don't support it.
Why AnimatePresence can't animate between routes
The usual first attempt is wrapping {children} in a layout with Motion's AnimatePresence (the tool for exit animations within a page). It doesn't work reliably: when you navigate, the App Router swaps the page segment straight away, so the old page has already been removed by the time an exit animation could run. Workarounds that freeze the old router context exist, but they depend on Next.js internals and break between versions.
View transitions avoid the problem entirely. The browser takes a picture of the old page, React renders the new one, and the browser animates between the two. Nothing needs to stay mounted.
A crossfade on every navigation
Route navigations in the App Router are React transitions, so a <ViewTransition> around a page's content animates whenever you navigate. The default animation is a crossfade:
import { ViewTransition } from "react";
export default async function Post({ params }: PageProps<"/blog/[slug]">) {
const { slug } = await params;
const post = await getPost(slug);
return (
<ViewTransition>
<article>
<h1>{post.title}</h1>
{/* … */}
</article>
</ViewTransition>
);
}Put the wrapper in each page.tsx, not in a layout: layouts stay mounted across navigations, so they never enter or exit.
Morph a thumbnail into a hero image
The most striking transition is a shared element: a card image on a list page that grows into the hero image on the detail page. Give both the same name and React pairs them up, animating size and position between the two:
import { ViewTransition } from "react";
import Link from "next/link";
export function PostCard({ post }: { post: Post }) {
return (
<Link href={`/blog/${post.slug}`}>
<ViewTransition name={`cover-${post.slug}`}>
<img src={post.cover} alt="" className="aspect-video rounded-xl object-cover" />
</ViewTransition>
<h2>{post.title}</h2>
</Link>
);
}Wrap the hero on the post page in a <ViewTransition> with the same name. The morph plays when the destination renders in the same commit as the navigation, which is the case for prefetched pages. If the new page shows a loading fallback first, there's no pair to morph and the content simply fades in when it arrives.
Slide forward and back
Direction helps people keep their place: moving deeper slides left, going back slides right. Tag links with transitionTypes, then map each type to a CSS class on the page's <ViewTransition>:
<Link href={`/blog/${post.slug}`} transitionTypes={["nav-forward"]}>
{post.title}
</Link>
// in each page that takes part
<ViewTransition
enter={{ "nav-forward": "nav-forward", "nav-back": "nav-back", default: "none" }}
exit={{ "nav-forward": "nav-forward", "nav-back": "nav-back", default: "none" }}
default="none"
>
{/* page content */}
</ViewTransition>::view-transition-old(.nav-forward) {
--slide-offset: -60px;
animation: 150ms ease-in both fade reverse, 400ms ease-in-out both slide reverse;
}
::view-transition-new(.nav-forward) {
--slide-offset: 60px;
animation: 210ms ease-out 150ms both fade, 400ms ease-in-out both slide;
}
/* nav-back is the same with the offsets swapped */
@keyframes fade {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slide {
from { translate: var(--slide-offset); }
to { translate: 0; }
}The browser's own back button doesn't carry a transition type, so it gets no slide; shared element morphs still play. default: "none" keeps untagged navigations, refreshes and loading states from sliding.
Keep the header still
If the whole page slides, the header slides with it, and people lose their anchor. Give the header its own transition name and switch its animation off:
/* on the header element: style={{ viewTransitionName: "site-header" }} */
::view-transition-group(site-header) {
animation: none;
z-index: 100;
}
::view-transition-old(site-header) {
display: none;
}
::view-transition-new(site-header) {
animation: none;
}
/* clicks during a transition reach the page instead of the overlay */
::view-transition {
pointer-events: none;
}Respect reduced motion
Sliding the whole viewport is the kind of movement that bothers people with motion sensitivity most (more on that in respecting prefers-reduced-motion in React). The simplest fix turns every view transition into an instant swap for anyone who asks for reduced motion:
@media (prefers-reduced-motion: reduce) {
::view-transition-old(*),
::view-transition-new(*),
::view-transition-group(*) {
animation-duration: 0s !important;
animation-delay: 0s !important;
}
}Where Motion still fits
View transitions handle the change between pages. Motion is still the better tool for what happens inside a page once it has arrived: staggered entrances, scroll-linked effects, gestures and springs. For a simple enter animation on every route, a template.tsx works too, because unlike a layout it remounts on each navigation:
"use client";
import { motion } from "motion/react";
export default function Template({ children }: { children: React.ReactNode }) {
return (
<motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.3, ease: [0.16, 1, 0.3, 1] }}>
{children}
</motion.div>
);
}That gives you an entrance only, with no exit, and it makes everything under it a client boundary's child, so prefer <ViewTransition> when you want both sides of the change.
Questions
Do view transitions work in every browser?
The basic View Transitions API is in all major browsers, and React's typed transitions need recent versions (Chromium 125 and newer, with recent Safari and Firefox). Where they're missing, navigation works normally and simply doesn't animate.
Do I need to enable anything in next.config?
No. The App Router supports React's ViewTransition with no configuration; you need a React version that includes it, such as the one bundled with Next.js 16.
Why doesn't AnimatePresence animate my page exits in Next.js?
Because the App Router removes the old page as soon as the new one renders, so there's nothing left for AnimatePresence to animate out. View transitions snapshot the old page instead, which is why they work.
Can I still use Framer Motion for page transitions?
For entrances, yes: a motion component in app/template.tsx animates every new page in. For exits and shared elements between pages, use ViewTransition.