Build and Debug Motion for React Animations

VerifiedSafe

Build and debug Motion for React animations using patterns from animations.dev. Covers springs, layout morphs, exit animations, drag gestures, and more.

Sby Skills Guide Bot
DevelopmentIntermediate
8/29/2026
Claude CodeCursorWindsurfCopilotCodex
#react#animation#motion#framer-motion#ui-components

Recommended for

Automated summary

A working reference for building and debugging animations with Motion for React (formerly Framer Motion), following the approach taught in the Animations on the Web course.

Strengths

  • Covers the whole practical surface: variants, AnimatePresence, layoutId, motion values, springs and drag gestures
  • Gives explicit guidance on when plain CSS is enough and when the library actually earns its bundle weight
  • Includes a debugging map for the usual failures: silent exit animation, distorted border radius on a morph, reversed direction-aware slide, jumping auto height
  • Points to RECIPES.md for full component builds such as the popover, multi-step flow and App Store card

Limitations

  • Assumes a React project that already ships Motion or is willing to add it; not framework-agnostic
  • Condensed course notes rather than a full replacement for the official API documentation
  • The component recipes live in a separate file that is not included here
When to use it

Reach for it whenever you write or fix a Motion for React animation involving exit transitions, layoutId morphs, spring tuning or motion values outside React's render cycle.

When not to use it

Skip it when the effect is cleanly achievable in pure CSS, or when you need guidance for a different animation library such as GSAP or React Spring.

Security analysis

Safe
Quality score85/100

This is a documentation/reference skill for the Motion for React (Framer Motion) library. It contains no tool invocations, no shell commands, no network calls, no file operations, and no instructions to exfiltrate data or disable safety. All code samples are ordinary JSX animation examples. No declared allowed-tools means nothing is invoked beyond the agent's normal text generation.

No concerns found

How this analysis is made

Examples

Exit animation not playing
My modal's exit animation never plays when I close it with AnimatePresence — it just disappears instantly. Here's my component code, can you fix it?
Shared element morph
I want a card thumbnail to smoothly morph into a full-screen detail view using layoutId in motion/react. Can you write the two components and handle the border radius distortion during the morph?
Direction-aware slide
I'm building a multi-step flow with Motion for React and my slide transition goes the wrong way when the user hits Back. How do I make it direction-aware with variants and a custom prop?

name: motion-react description: Build animations with Motion for React (motion/react, formerly Framer Motion) the way the "Animations on the Web" course (animations.dev) teaches — and debug them when the magic misfires. Use when writing motion components, exit animations, layout or shared-element morphs, springs, motion values, or drag gestures; when deciding whether a job needs the library at all; or when an exit animation won't play, a morph distorts its border radius, a direction-aware slide points the wrong way, or an auto height jumps. Triggers on — motion/react, framer-motion, motion.div, initial animate exit, AnimatePresence, popLayout, mode wait, layout animation, layoutId, shared element transition, variants, custom prop, MotionConfig, useMotionValue, useSpring, useTransform, useMotionTemplate, useInView, useReducedMotion, useAnimate, useMeasure, animate height auto, drag, dragConstraints, dragMomentum, whileTap, spring bounce, stiffness, damping. metadata: short-description: Build and debug Motion for React animations (animations.dev)

Motion for React

The Framer Motion module of Emil Kowalski's Animations on the Web course (animations.dev), as a working reference.

Framer Motion is now Motion for React. Nothing changed but the import path:

import { motion, AnimatePresence } from "motion/react";  // was "framer-motion"

For the component builds — feedback popover, multi-step flow, trash interaction, interactive graph, App Store card — load RECIPES.md.

Reach for it only when CSS can't

Everything Motion does is possible in vanilla CSS and JS. It just takes far longer. Emil's own default is to skip the library when CSS gets there in reasonable time — enter/exit for modals and dropdowns via Radix's [data-state] attributes covers most of it, since Radix suspends unmount while a closing animation plays.

Reach for Motion when CSS genuinely can't:

  • Real spring physics — interruptible motion that keeps momentum.
  • Layout changes, including properties CSS can't animate at all (flex-direction, justify-content).
  • Shared-element morphs — one element becoming another (layoutId).
  • Animating out unmounted components (AnimatePresence) — hard in React, because the component is already gone.

The deciding factor is usually bundle size and what the project already ships. Vercel kept Motion out of the Next.js docs and rewrote a copy-button animation in CSS to save the weight; in Clerk's dashboard, which already had it, Emil reaches for it freely to save time and keep the code readable.

The cost of all this: magic. Complex animations come out of very little code, so when something misbehaves you're debugging a black box, and the docs mostly follow the happy path. The Debugging section below is the map for that.

Basics

<motion.div
  initial={{ opacity: 0, scale: 0.95 }}
  animate={{ opacity: 1, scale: 1 }}
/>

initial is the start state, animate the end state. Values are interpolated in JavaScript, outside React's render cycle — an animating component doesn't re-render, which is what makes 60fps achievable.

Transitions and springs

Without a transition, Motion picks per value type: physical values (x, scale) get a spring, everything else (opacity, color) gets a tween.

transition={{ duration: 0.3, ease: "easeOut" }}                          // tween
transition={{ type: "spring", duration: 0.3, bounce: 0 }}                // state swaps, no overshoot
transition={{ type: "spring", duration: 0.5, bounce: 0.2 }}              // slight, lively overshoot
transition={{ type: "spring", stiffness: 100, damping: 10, mass: 0.75 }} // physics form

Pull repeated spring configs into a constant. When a spring looks wrong — jittery, overshooting oddly — raise damping; that fixes it most of the time. Lower mass makes it track an input more tightly (a cursor follower wants mass: 0.1).

MotionConfig sets a default transition for a whole subtree, so a component reads as one entity instead of a pile of individually-tuned parts:

<MotionConfig transition={{ type: "spring", duration: 0.5, bounce: 0.2 }}>…</MotionConfig>

AnimatePresence

<AnimatePresence mode="popLayout" initial={false} custom={direction}>
  <motion.span
    key={state}          // REQUIRED
    custom={direction}   // pass again, or the exiting element reads stale props
    initial={{ opacity: 0, y: -25 }}
    animate={{ opacity: 1, y: 0 }}
    exit={{ opacity: 0, y: 25 }}
    transition={{ type: "spring", duration: 0.3, bounce: 0 }}
  />
</AnimatePresence>
  • A key is mandatory. Without it the component never unmounts and the exit never fires. When an exit animation does nothing, check the key first.
  • mode="wait" — the old element leaves completely before the new one enters. For icon swaps (copy → checkmark) and morphing one rich state into another.
  • mode="popLayout" — old and new animate simultaneously while siblings reflow around them. The right default for state swaps inside a button, step transitions, and crossfades. If an exit animation looks broken, try changing mode before anything else.
  • initial={false} skips the mount animation, so a state swap doesn't animate on first paint.
  • An exiting element's props are stale. It has already been removed from the tree, so it can't see the newest state. Pass custom to both AnimatePresence and the motion element to feed it fresh data — this is what makes direction-aware slides work.

Variants

Named target sets, reusable across initial/animate/exit. Their real power is the function form, which receives custom:

const variants = {
  initial: (direction) => ({ x: `${110 * direction}%`, opacity: 0 }),
  active:  { x: "0%", opacity: 1 },
  exit:    (direction) => ({ x: `${-110 * direction}%`, opacity: 0 }),
};

<motion.div variants={variants} initial="initial" animate="active" exit="exit" custom={direction} />

Store the direction in state (setDirection(1) on next, -1 on back) at the same time you change the step.

Layout and shared-element animations

The layout prop is the library's most powerful feature and the reason its animations feel native.

  • layout animates any layout change — position, size, flex-direction, justify-content. For layout animations you change the element's actual styles (className or inline), not the animate prop; Motion measures before and after and interpolates.
  • Add layout to neighbouring elements too, or they'll jump while the animating one glides.
  • layoutId connects two different elements: when one mounts carrying the same layoutId as one that just unmounted, Motion morphs between them. Tab indicators, App Store card → detail, button → popover, images flying into a bin.
  • You can't steer a shared layout animation. To add motion on top, animate the parent and let the children come along: <motion.div animate={{ y: 73 }} transition={{ delay: 0.13 }}>.
  • Always set an animated border-radius as an inline pixel value — style={{ borderRadius: 12 }}. Layout animations work by scaling, which distorts corners; Motion corrects for this only when the radius is in pixels, not from a class or a rem value.

Expect friction on complex cases — distortion, elements that won't line up. That's the magic tax. Inside Framer's Magic Motion explains the mechanism if you need to reason about it.

Animating height

Motion can animate a fixed height to auto, but not auto → auto — which is what dynamic content actually needs. Measure it:

import useMeasure from "react-use-measure";

const [ref, bounds] = useMeasure();

<motion.div animate={{ height: bounds.height ? bounds.height : null }}>
  <div ref={ref} className="inner">{content}</div>
</motion.div>
  • The ref and the animate={{ height }} must be on different elements. On the same one, the animated height sticks and the element stops reacting to content changes.
  • Put the padding on the inner element so the measurement includes it.
  • bounds.height is 0 on first render; falling back to null means auto and avoids a layout shift.
  • useMeasure is a ResizeObserver wrapper — hand-rolling one is a few lines if you'd rather not add the dependency.

Motion values

Motion values update outside React's render cycle, so a value can change 60 times a second without a single re-render. Use them for anything high-frequency — pointer tracking above all. The React-state version of a cursor follower re-renders on every mouse move; the motion-value version doesn't re-render at all.

const x = useMotionValue(0);                                  // .set() / .get()
<motion.div style={{ x }} />                                  // x/y map to translateX/translateY

| Hook | Use it for | | --- | --- | | useMotionValue | The value must track an input 1:1 — drag-to-dismiss scale, anything where a spring would feel disconnected from the finger. | | useSpring | Almost everything else. A raw motion value updates instantly and feels lifeless; a spring makes the same interaction feel alive. | | useTransform | Map one motion value's range onto another: useTransform(y, [0, 300], [1, 1.5]). The function form transforms the output instead — useful for animating a displayed number, and it stays subscribed so the rendered text keeps up. | | useMotionTemplate | Build a reactive string from motion values — a motion value dropped into a plain template literal is dead. This is how you animate clipPath, filter, or any composite string. |

const label = useTransform(angle, (v) => `${Math.round(v)}°`);          // function form
const clip  = useMotionTemplate`inset(0px ${clipValue}% 0px 0px)`;      // tagged template

useSpring genuinely changes how an interaction feels — the difference between a graph that follows your cursor and one that merely tracks it. Don't skip it to save a hook.

Gestures

<motion.div drag dragConstraints={boxRef} dragMomentum={false} whileTap={{ scale: 0.97 }} />

drag keeps momentum on release by default, which feels natural for a card being flung and wrong for a simple reposition — turn it off with dragMomentum={false}. dragConstraints takes a ref and bounds the element to it.

Accessibility

  • useReducedMotion() branches values in a component; <MotionConfig reducedMotion="user"> handles a whole app by animating only opacity and background.
  • Reduced motion means gentler, not none — keep opacity and color, drop the movement.
  • If you fake a placeholder with a real element (see the feedback popover), keep the input's actual placeholder attribute for screen readers and aria-hidden the fake one.

Debugging the magic

| Symptom | Cause | | --- | --- | | Exit animation doesn't play | Missing key, so the component never unmounts. Then: wrong mode. | | Direction-aware slide always goes the same way | The exiting element has stale props — pass custom to both AnimatePresence and the element. | | Border radius warps during a morph | Radius came from a class or rem. Move it to inline style={{ borderRadius: 12 }}. | | Height animation freezes or jumps | ref and animate={{ height }} are on the same element, or the first-render 0 isn't falling back to null. | | Neighbouring elements jump during a layout animation | They need layout too. | | A useMotionTemplate-less string never updates | Motion values aren't reactive inside plain template literals. | | Spring looks jittery or wild | Raise damping. | | Both elements visible at once when switching fast | A known AnimatePresence bug; if you can't work around it, 11.0.10 predates it. | | Animation runs on first paint when it shouldn't | Add initial={false} to AnimatePresence. |

Imperative animation

useAnimate() gives you [scope, animate] for low-level, selector-based control. It's more powerful and much harder to maintain — Emil almost never uses it. Stay declarative unless you're orchestrating many elements across events.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/build-and-debug-motion-for-react-animations-mte1lgw6/download' --output '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md.part' && mv '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md.part' '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md' && test -s '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/motion-react' && cp -R '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6' '.claude/skills/motion-react'

Cursor
test -f '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md' && test -s '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/motion-react' && cp -R '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6' '.cursor/skills/motion-react'

Codex
test -f '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md' && test -s '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/motion-react' && cp -R '.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6' '.agents/skills/motion-react'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6'

openskills read 'build-and-debug-motion-for-react-animations-mte1lgw6'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/build-and-debug-motion-for-react-animations-mte1lgw6/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills