The animate Prop: Declarative Target States
You'll learn how to tell Framer Motion where an element should animate to using a simple object syntax.
What Is a Target State?
Think of the animate prop like giving GPS coordinates to your animation. Instead of manually scripting every step of an animation, you simply declare the final destination—Framer Motion handles the journey for you.
With the motion component you just learned, you can pass an animate prop that describes the end state of your animation using style values:
<motion.div
animate={{ opacity: 1, x: 100 }}
>
I'll animate to these values!
</motion.div>
How It Works
The animate prop accepts an object where keys are CSS properties (written in camelCase) and values are the target you want to animate to:
<motion.div
animate={{
x: 200, // translateX by 200px
scale: 1.5, // scale up to 150%
rotate: 45, // rotate 45 degrees
opacity: 0.8, // fade to 80% opacity
backgroundColor: "#ff0000" // change color
}}
>
Multiple properties!
</motion.div>
Notice you don't write CSS strings—just values. Framer Motion understands units like pixels, degrees, and percentages automatically.
Declarative Philosophy
This is declarative: you describe what you want, not how to get there. Change the animate prop's values, and the element smoothly animates to the new state:
const [isExpanded, setIsExpanded] = useState(false);
<motion.div
animate={{
width: isExpanded ? 300 : 100
}}
>
Toggle me
</motion.div>
When isExpanded changes, the animation happens automatically.
Key Takeaway: The animate prop takes an object of CSS properties and target values, declaratively defining where your element should animate to—Framer Motion automatically creates the smooth transition.