Installation
Install Framer Motion via npm or yarn:Basic usage
Framer Motion provides a simple yet powerful API for React animations. The core component ismotion, which can be applied to any HTML or SVG element.
Hover and tap gestures
Add interactive animations that respond to user input:Exit animations with AnimatePresence
Animate components when they’re removed from the React tree:Key features
Declarative API
Define animations directly in your JSX with intuitive props like
animate, initial, and exit.Gesture support
Built-in support for drag, hover, tap, and pan gestures with
whileHover, whileTap, and drag props.Spring physics
Natural-feeling animations using spring physics with customizable stiffness and damping.
Motion values
Create linked animations with
useMotionValue and useTransform for advanced effects.Drag gestures
Create draggable elements with constraints and elastic behavior:Scroll-based animations
Create animations that respond to scroll position:Reorderable lists
Build drag-to-reorder lists with smooth animations:When to use it
Prototyping and production
Prototyping and production
Framer Motion excels at both rapid prototyping and production-ready animations. Its declarative API makes it easy to experiment with different animation styles.
Interactive UI components
Interactive UI components
Perfect for creating interactive components like modals, dropdowns, tooltips, and navigation menus that need smooth enter/exit animations.
Gesture-based interactions
Gesture-based interactions
Ideal when you need drag-and-drop functionality, swipeable cards, or other gesture-driven interfaces.
Complex orchestration
Complex orchestration
Use variants and orchestration features to coordinate multiple animations across different components.
Performance tips
- Use
transformandopacityproperties for better performance - Enable GPU acceleration with
transform: translateZ(0) - Use
layoutanimations for automatic layout transitions - Respect
prefers-reduced-motionfor accessibility
Learn more
Animation examples
Explore practical animation examples
Official docs
Visit the Framer Motion documentation