Well-placed motion makes an interface easier to follow: it shows where something came from, confirms an action and guides attention. Badly placed motion makes it feel slow and distracting. Motion for React, the library formerly known as Framer Motion, makes the good kind straightforward.
Framer Motion is now Motion
In late 2024 Framer Motion became an independent project called Motion. New projects install the motion package and import from motion/react; existing projects using framer-motion keep working, and the API is the same. The examples below apply to both.
The basics: initial, animate and transition
Any HTML or SVG element has a motion version. You describe where it starts and where it ends, and Motion animates between them:
import { motion } from 'motion/react';
export function Notice() {
return (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.3 }}
>
Your changes were saved
</motion.div>
);
}
Motion uses spring physics for physical properties like position and scale by default, which is why its animations feel natural without hand-tuned easing curves.
Orchestrating lists with variants
Variants are named animation states. A parent can pass its state down, and staggerChildren animates each child a little after the previous one:
const list = {
hidden: { opacity: 0 },
show: { opacity: 1, transition: { staggerChildren: 0.06 } },
};
const item = { hidden: { opacity: 0 }, show: { opacity: 1 } };
<motion.ul variants={list} initial="hidden" animate="show">
{items.map(i => <motion.li key={i.id} variants={item}>{i.name}</motion.li>)}
</motion.ul>
Keep staggers short. Around 50 milliseconds per item feels lively; 200 milliseconds per item makes a long list feel like it is loading.
Exit animations with AnimatePresence
React removes elements from the page immediately, so there is nothing left to animate. Wrapping conditional content in AnimatePresence lets Motion keep the element around until its exit animation finishes:
<AnimatePresence>
{open && (
<motion.div
key="panel"
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: 'auto' }}
exit={{ opacity: 0, height: 0 }}
/>
)}
</AnimatePresence>
Each direct child needs a stable key, so Motion can tell which element is leaving.
Layout animations
Adding the layout prop makes an element animate smoothly whenever its size or position changes because of a React re-render: a card expanding, a list being filtered, a tab indicator sliding to the active tab. Motion measures the before and after positions and animates the difference using transforms, which keeps it smooth.
For an element that moves between two different components, such as a highlight under the active tab, give both a shared layoutId and Motion animates one into the other.
Scroll-linked effects, with care
useScroll and useTransform connect a value to scroll position, for progress bars or subtle parallax on images. Use this sparingly. Text that slides around while someone is reading is distracting; reveals are usually better as a simple fade with no movement.
Respect reduced motion
Some people get dizzy or nauseous from motion, and they tell their operating system so. Wrap your app in MotionConfig with reducedMotion="user" and Motion will skip transform and layout animations for them while keeping fades:
<MotionConfig reducedMotion="user">
<App />
</MotionConfig>
For custom cases, the useReducedMotion hook returns whether the user has asked for less motion.
Keep it fast
- Animate transform and opacity. These run on the compositor and stay smooth. Animating width, height, top or margin forces layout work on every frame.
- Load less.
LazyMotionwith the lighter feature bundle and themcomponent cuts the initial download if you only need basic animations. - Avoid animating huge blurred areas. Big blur filters and shadows are expensive to repaint, particularly on phones.
- Let hover effects be hover effects. On touch devices they never fire, so never hide essential information behind them.
Where motion earns its place
- Confirming an action: a button that compresses on press, a toast that slides in.
- Showing relationships: a card that expands into a detail view.
- Directing attention: a gentle highlight on a newly added item.
- Smoothing state changes: content that fades rather than snapping.
Where it does not
- Long entrance animations before content is readable.
- Motion on every element of a page at once.
- Anything that delays a user who already knows what they want.
The best animation is the one users do not consciously notice: it simply makes the interface easier to understand.
