framer-motion
Framer Motion is the most popular animation library for React, providing a simple declarative API for creating complex animations, gestures, and layout transiti…
Installation
npm install framer-motion
yarn add framer-motion
pnpm add framer-motion
Import
import { motion, AnimatePresence } from 'framer-motion';Quick Example
import { motion } from 'framer-motion';
function Card() {
return (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
whileHover={{ scale: 1.05 }}
transition={{ type: 'spring', stiffness: 300 }}
>
<h2>Animated Card</h2>
</motion.div>
);
}About framer-motion
Framer Motion is the most popular animation library for React, providing a simple declarative API for creating complex animations, gestures, and layout transitions. The library's core concept is the motion component — any HTML or SVG element prefixed with motion (motion.div, motion.button) gains animation capabilities through props. The animate prop defines the target state, initial sets the starting state, and Framer Motion automatically interpolates between them with spring physics by default. The library handles enter/exit animations through AnimatePresence, shared layout animations with layoutId for morphing elements between different components, scroll-triggered animations, drag gestures with constraints and inertia, hover and tap animations, and orchestrated stagger animations. Framer Motion provides variants for defining named animation states and orchestrating complex sequences across component hierarchies. The useMotionValue and useTransform hooks enable creating derived animated values and parallax effects. The library supports SVG path animation, keyframe sequences, and spring/tween/inertia transition types. Framer Motion's API is more intuitive than CSS animations for complex scenarios and significantly simpler than GSAP or React Spring for most React use cases.
Quick Facts
| Package | framer-motion |
| Category | UI Component |
| Weekly Downloads | 5M+ |
| License | MIT |
| Install | npm install framer-motion |
Related Packages
React Spring is a spring-physics-based animation library for React that covers most UI animation nee…
React is the most popular JavaScript library for building user interfaces, developed and maintained …
Lottie Web is a library for rendering Adobe After Effects animations exported as JSON files through …
Three.js is the most popular JavaScript library for creating and displaying 3D graphics in web brows…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.