Introduction
Get started with Framer Motion and learn by exploring interactive examples.
#Overview
Framer Motion is a simple yet powerful motion library for React.
It powers the amazing animations and interactions in Framer, the web builder for creative pros. Zero code, maximum speed.
#Install
Framer Motion requires React 18. Install framer-motion
from npm:
npm install framer-motion
Users already upgrading to React 19 can install the Framer Motion 12 alpha, which currently works with the React 19 RC:
npm install framer-motion@12.0.0-alpha.0
#Importing
Once installed, you can import Framer Motion via framer-motion
.
// Reactimport { motion } from "framer-motion"
// React Server Componentsimport * as motion from "framer-motion/client"
In this quick overview, we'll take a look at some of the APIs that Motion offers.
#Usage
#The <motion />
component
The core of Motion is the motion component. Think of it as a plain HTML or SVG element, supercharged with animation capabilities.
<motion.div />
#Animations
Animating a motion
component is as straightforward as setting values on the animate prop.
<motion.div animate={{ x: 100 }} />
When these values change, Framer Motion will automatically generate an animation to the latest values. This animation will feel great by default, but it can be configured with the flexible transition prop.
#Gestures
<motion />
extends React's event system with powerful gesture recognisers. It supports hover, tap, pan and drag.
<motion.div whileHover={{ scale: 1.2 }} whileTap={{ scale: 1.1 }} drag="x" dragConstraints={{ left: -100, right: 100 }}/>
#Variants
Variants can be used to animate entire sub-trees of components with a single animate
prop. Options like when
and staggerChildren
can be used to declaratively orchestrate these animations.
const list = { hidden: { opacity: 0 } }const item = { hidden: { x: -10, opacity: 0 } }
return ( <motion.ul animate="hidden" variants={list}> <motion.li variants={item} /> <motion.li variants={item} /> <motion.li variants={item} /> </motion.ul>)
#Scroll-triggered animations
Elements can animate as they enter and leave the viewport with the handy whileInView
prop.
<motion.div initial={{ opacity: 0 }} whileInView={{ opacity: 1 }}/>
#Server-side rendering
The animated state of a component will be rendered server-side to prevent flashes of re-styled content after your JavaScript loads.
<motion.div initial={false} animate={{ x: 100 }} />
#MotionValues
MotionValues
are used to track the state and velocity of animating values, outside of React's render lifecycle.
They're created automatically and used internally by motion
components. But they can also be created manually and chained together to create performant, declarative effects.
const x = useMotionValue(0)const opacity = useTransform(x, [-100, 0, 100], [0, 1, 0])
return <motion.div drag="x" style={{ x, opacity }} />
#Layout animations
Framer Motion is capable of animating changes in layout using performant transforms.
<motion.div layout />
#Manual animations
The useAnimate
hook can be used to manually trigger animations in effects and event handlers. It can also be used to orchestrate more complex animations.
<div onClick={() => animate(".boxes", { opacity: 0 })} />