Content
Motion (Framer Motion)
Production-ready animation library for React. Use for component-level motion, layout transitions, gesture responses, and exit animations.
Core concepts
- motion components —
<motion.div>wraps any HTML or SVG element with animation superpowers - variants — named animation states that propagate through component trees
- layout animations — automatic interpolation when elements change position or size
- AnimatePresence — animate components as they mount and unmount
- gestures —
whileHover,whileTap,whileDrag,whileFocus
When to use
| Scenario | Motion? |
|---|---|
| Component enter/exit | Yes — AnimatePresence |
| Layout shifts (reorder, resize) | Yes — layout prop + layoutId for shared layouts |
| Hover/press micro-interactions | Yes — gesture props |
| Scroll-driven pinning or scrubbing | Mixed — consider native browser scroll-driven animations where available; for complex scrubbing or timelines use GSAP ScrollTrigger |
| Page route transitions | Yes — prefer the browser View Transitions API when supported (see Compatibility) and fall back to AnimatePresence + |