Page transition
Also called route transition or navigation transition
An animation that plays when you move from one page or screen to another, such as the old page fading out as the new one fades in.
import { useState } from 'react';
import { AnimatePresence, motion, MotionConfig } from 'motion/react';
const pages = {
home: {
title: 'Build apps by describing them',
text: 'Tell the agent what you need and watch it come together.'
},
pricing: {
title: 'Simple pricing',
text: 'Start free. Upgrade when your app takes off.'
},
docs: {
title: 'Documentation',
text: 'Guides for building, previewing, and publishing.'
}
};
type Page = keyof typeof pages;
export function SiteShell() {
const [page, setPage] = useState<Page>('home');
return (
// reducedMotion='user' drops the slide and keeps a plain fade.
<MotionConfig reducedMotion='user'>
{/* The header stays still; only the main content transitions. */}
<header className='flex gap-6 border-b px-6 py-4 text-sm'>
{(Object.keys(pages) as Page[]).map((key) => (
<button
key={key}
type='button'
aria-current={key === page ? 'page' : undefined}
onClick={() => setPage(key)}
className='font-medium text-muted-foreground capitalize aria-[current=page]:text-foreground'
>
{key}
</button>
))}
</header>
{/* With a router, key on the pathname. popLayout lets the old and new pages overlap. */}
<div className='relative'>
<AnimatePresence mode='popLayout' initial={false}>
<motion.main
key={page}
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.25, ease: [0.23, 1, 0.32, 1] }}
className='px-6 py-10'
>
<h1 className='text-2xl font-semibold'>{pages[page].title}</h1>
<p className='mt-2 text-muted-foreground'>{pages[page].text}</p>
</motion.main>
</AnimatePresence>
</div>
</MotionConfig>
);
}Add a page transition to the site: when navigating between pages, fade the old main content out and fade the new content in while it slides up 8px, 250ms total with ease-out. Keep the header and navigation static, never delay the navigation for the animation, and disable the motion when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Page transition?
Without a page transition, clicking a link swaps the whole screen at once. A page transition animates the handoff: the outgoing page fades or slides away while the incoming page arrives, usually within 200 to 400ms. Mobile apps have always done this, and websites increasingly do too.
Pick one style and use it everywhere. A quick crossfade suits most sites. A slide works when pages have a clear order, such as tabs or steps, and should follow the direction of travel. Keep shared parts like the header and navigation still, so only the content area moves.
A page transition should never slow people down. Start it right away instead of waiting for data, keep it short, and respect prefers-reduced-motion. In React apps you can animate the route content with a library like Motion, or use the browser’s View Transitions API, which works within a single-page app and, in supporting browsers, across regular page loads.
Often confused with
- View Transitions API
- A page transition is the effect. The View Transitions API is one browser feature for building it, by snapshotting the old page and animating to the new one.
Related terms
All termsCrossfade
A transition where the old content fades out while the new content fades in at the same spot, so the two briefly overlap.
Direction-aware transition
A transition that slides new content in from the side you are heading toward, so going forward and going back move in opposite directions.
Shared element transition
A transition where an element from one view, like a thumbnail, travels and grows into its place in the next view, linking the two screens.
Perceived performance
How fast an app feels to people, which skeleton screens, instant feedback, and progressive loading can improve even when the real wait stays the same.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.