motionkit.byHizmedia (opens hizmedia.com in a new tab)
ComponentsTheme StudioPage BuilderPricing

Start building with motion.

206 animated React components, free to browse and customise. Plus unlocks every premium one, with a 14-day free trial.

Browse componentsSee Plus
motionkit.

Animated React components for people who love the details. Built with TypeScript, Tailwind CSS and Motion.

  • Hizmedia on Instagram (opens in a new tab)
  • Hizmedia on LinkedIn (opens in a new tab)
  • Hizmedia on YouTube (opens in a new tab)

Product

  • Components
  • Theme Studio
  • Page Builder
  • MotionKit Plus
  • What's new

Components

  • Backgrounds
  • Text effects
  • Buttons
  • Cards
  • Sections
  • All 206 components

Resources

  • Guides
  • Free tools
  • Free components
  • For shadcn/ui
  • Liquid glass
  • Hero sections

Company

  • About
  • Cookie policy
  • Your account
  • Hizmedia (opens in a new tab)
  • Start a project

motionkit.

© 2026 Hizmedia (opens hizmedia.com in a new tab)· Designed and built in the UK

RSS Back to top
    1. Guides
    2. Build it

    Page Transitions in the Next.js App Router with View Transitions

    Animate between pages in the Next.js App Router with React's ViewTransition: shared element morphs, directional slides, a fixed header and reduced motion, plus when Motion still helps.

    HHizmediaUpdated 14 November 20268 min read
    On this page
    1. 01Why AnimatePresence can't animate between routes
    2. 02A crossfade on every navigation
    3. 03Morph a thumbnail into a hero image
    4. 04Slide forward and back
    5. 05Keep the header still
    6. 06Respect reduced motion
    7. 07Where Motion still fits

    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.

    01Why 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.

    02A 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:

    app/blog/[slug]/page.tsx
    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.

    03Morph 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:

    components/post-card.tsx
    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.

    04Slide 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>:

    app/blog/page.tsx
    <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>
    app/globals.css
    ::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.

    05Keep 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:

    app/globals.css
    /* 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;
    }

    06Respect 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:

    app/globals.css
    @media (prefers-reduced-motion: reduce) {
      ::view-transition-old(*),
      ::view-transition-new(*),
      ::view-transition-group(*) {
        animation-duration: 0s !important;
        animation-delay: 0s !important;
      }
    }

    07Where 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:

    app/template.tsx
    "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.

    Put it into practice

    Components from this guide

    • Photo FanA little pile of instant photos that fans out like a hand of cards on hover, each print lifting clear as you point at it.
    • Card StackA deck you swipe through: fling the top card and it tucks in at the back.
    • Animated TabsAccessible tabs with a sliding indicator and soft content transitions.
    • Expand CardCards that morph smoothly into a full detail view, then fold back into place.

    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.

    PreviousAnimated Hero Sections in Next.js That Stay FastNext Custom Animations in Tailwind CSS v4: Keyframes, Easing and Enter Effects

    On this page

    1. Why AnimatePresence can't animate between routes
    2. A crossfade on every navigation
    3. Morph a thumbnail into a hero image
    4. Slide forward and back
    5. Keep the header still
    6. Respect reduced motion
    7. Where Motion still fits

    Found this useful? Send it to someone building with motion.

    Keep reading

    All guides
    • Fundamentals·5 min read

      Stagger Animations in React with Motion

      How to stagger animations in React with Motion's stagger(): lists, grids and text, starting from the first, last or centre item, and how long to make them.

      Read guide
    • Fundamentals·7 min read

      Exit Animations in React: AnimatePresence and Why Yours Isn't Working

      Why Motion's exit animations don't play and how to fix them: where AnimatePresence goes, keys, mode="wait" and popLayout, lists, Next.js routes, and CSS-only exits for dialogs.

      Read guide
    • Fundamentals·7 min read

      Scroll Animations in React: whileInView, useScroll and IntersectionObserver

      Three ways to animate on scroll in React: reveal with whileInView, follow scroll position with useScroll, or use IntersectionObserver directly.

      Read guide