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. Fundamentals

    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.

    HHizmediaUpdated 14 November 20267 min read
    On this page
    1. 01The pattern that works
    2. 02Mistake 1: AnimatePresence is inside the condition
    3. 03Mistake 2: missing or unstable keys
    4. 04Mistake 3: the old and new content overlap
    5. 05Mistake 4: expecting it to work between Next.js routes
    6. 06Exit animations without JavaScript
    7. 07Reduced motion

    React removes elements immediately, so there's normally no moment to animate them out. Motion's `AnimatePresence` creates that moment: it keeps a removed child on screen until its `exit` animation finishes. When an exit animation silently doesn't play, it's almost always one of a handful of mistakes, each with a one-line fix.

    01The pattern that works#

    AnimatePresence stays mounted, and the element inside it is what comes and goes. The element needs an exit prop describing how it leaves:

    notice.tsx
    "use client";
    
    import { AnimatePresence, motion } from "motion/react";
    
    export function Notice({ show }: { show: boolean }) {
      return (
        <AnimatePresence>
          {show && (
            <motion.div
              key="notice"
              initial={{ opacity: 0, y: 8 }}
              animate={{ opacity: 1, y: 0 }}
              exit={{ opacity: 0, y: -8 }}
            >
              Saved
            </motion.div>
          )}
        </AnimatePresence>
      );
    }

    02Mistake 1: AnimatePresence is inside the condition#

    If AnimatePresence is removed along with its child, there's nothing left to run the exit. This is the most common cause:

    wrong.tsx
    // ✗ AnimatePresence disappears with the element
    {show && (
      <AnimatePresence>
        <motion.div exit={{ opacity: 0 }} />
      </AnimatePresence>
    )}
    
    // ✓ AnimatePresence stays, the element inside it goes
    <AnimatePresence>
      {show && <motion.div key="box" exit={{ opacity: 0 }} />}
    </AnimatePresence>

    03Mistake 2: missing or unstable keys#

    AnimatePresence tracks its direct children by key. Without one, swapping one element for another looks like an update rather than a removal, so nothing exits. In lists, using the array index as the key makes the wrong item animate out, because keys shift when an item is removed. Use an id that belongs to the item:

    list.tsx
    <AnimatePresence>
      {items.map((item) => (
        <motion.li key={item.id} exit={{ opacity: 0, height: 0 }}>
          {item.label}
        </motion.li>
      ))}
    </AnimatePresence>

    To swap content in place, like the steps of a form, change the key and the old step exits while the new one enters.

    04Mistake 3: the old and new content overlap#

    By default, the entering element appears while the old one is still leaving. For swaps, choose a mode:

    • mode="wait": the new element waits until the old one has finished exiting. Best for swapping one thing for another, like steps or tab panels.
    • mode="popLayout": the exiting element is taken out of the layout straight away, so siblings move into its space while it animates out. Best for lists and stacks, paired with the layout prop on the siblings.
    steps.tsx
    <AnimatePresence mode="wait" initial={false}>
      <motion.div
        key={step}
        initial={{ opacity: 0, x: 24 }}
        animate={{ opacity: 1, x: 0 }}
        exit={{ opacity: 0, x: -24 }}
        transition={{ duration: 0.2 }}
      >
        <Step number={step} />
      </motion.div>
    </AnimatePresence>

    initial={false} stops the first step from animating in when the page loads.

    05Mistake 4: expecting it to work between Next.js routes#

    Wrapping a layout's {children} in AnimatePresence doesn't animate page exits in the App Router, because the router replaces the old page before Motion can keep it. For transitions between pages, use React's <ViewTransition>, which snapshots the old page instead: see page transitions in the Next.js App Router.

    06Exit animations without JavaScript#

    For elements the browser shows and hides itself, such as <dialog> and popovers, CSS can now animate both ways. transition-behavior: allow-discrete lets display wait for the transition, and @starting-style sets where the entrance begins:

    dialog.css
    dialog {
      opacity: 0;
      translate: 0 8px;
      transition: opacity 0.2s, translate 0.2s, display 0.2s allow-discrete, overlay 0.2s allow-discrete;
    }
    
    dialog[open] {
      opacity: 1;
      translate: 0 0;
    }
    
    @starting-style {
      dialog[open] {
        opacity: 0;
        translate: 0 8px;
      }
    }

    Anything React removes from the page still needs AnimatePresence. For a working example of exits in a list, the Notification Bell and Tag Input components both use it.

    07Reduced motion#

    Wrap your app in <MotionConfig reducedMotion="user"> and Motion drops transform and layout animations for people who ask for reduced motion, while keeping opacity fades. Exits then become quick fades instead of movement.

    Put it into practice

    Components from this guide

    • ToastStacking notifications with swipe-to-dismiss, hover-to-pause and variants.
    • Notification BellPlusA bell that swings when something new arrives, with a popping unread badge and a panel of notifications you can swipe away.
    • Tag InputA text field that turns what you type into chips that spring into place. Paste a list to add several, and Backspace twice to remove the last.
    • AccordionFAQ panels that open with a smooth, springy height and a turning chevron.

    Questions

    Why is my Framer Motion exit animation not working?+

    Usually because AnimatePresence is inside the condition that removes the element, or the element has no key. Keep AnimatePresence mounted, put the condition inside it, and give each child a stable key.

    Does the exit prop work without AnimatePresence?+

    No. Without AnimatePresence, React removes the element immediately and the exit animation never starts.

    What's the difference between mode="wait" and mode="popLayout"?+

    wait holds the new element back until the old one has left, which suits swapping content. popLayout removes the old element from the layout immediately so the rest of the page can reflow while it animates out, which suits lists.

    Can I animate a page leaving in the Next.js App Router?+

    Not with AnimatePresence. Use React's ViewTransition, which works with the App Router's navigations.

    PreviousCustom Animations in Tailwind CSS v4: Keyframes, Easing and Enter EffectsNext Migrating from Framer Motion to Motion: What Changes

    On this page

    1. The pattern that works
    2. Mistake 1: AnimatePresence is inside the condition
    3. Mistake 2: missing or unstable keys
    4. Mistake 3: the old and new content overlap
    5. Mistake 4: expecting it to work between Next.js routes
    6. Exit animations without JavaScript
    7. Reduced motion

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

    Keep reading

    All guides
    • Fundamentals·9 min read

      Motion (Framer Motion) vs CSS Animations in React: Which to Use When

      Should you animate with CSS or Motion (Framer Motion) in React? Compare performance, bundle size, springs, exits and gestures, with code for both.

      Read guide
    • Build it·8 min read

      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.

      Read guide
    • Fundamentals·6 min read

      Easing Functions Explained: cubic-bezier in CSS and Motion

      What easing curves are, what ease-in, ease-out and ease-in-out really mean, how cubic-bezier works and which curve to use when, with a live curve editor.

      Read guide