Variants for Complex Orchestration
You'll learn how to use named animation states in Framer Motion to coordinate sophisticated animations across multiple components simultaneously.
What Are Variants?
Instead of defining animation properties directly on each motion component, variants let you create named animation states (like "hidden", "visible", or "selected") in a centralized object. You can then reference these states by name across your component tree, and Framer Motion automatically orchestrates the timing for child components.
Think of variants like a conductor's musical score: rather than telling each musician individually when to play their note, the conductor signals "allegro" or "forte," and everyone knows their part. Similarly, a parent component can set a variant state, and all children with matching variant names respond in coordination.
Why Use Variants?
Variants solve three key challenges:
- Centralized control - Change one parent's state to trigger animations throughout a component tree
- Automatic staggering - Children animate in sequence without manual delay calculations
- Cleaner code - Animation logic lives in reusable objects instead of scattered inline props
Basic Structure
const listVariants = {
hidden: { opacity: 0 },
visible: {
opacity: 1,
transition: { staggerChildren: 0.1 }
}
};
const itemVariants = {
hidden: { y: 20, opacity: 0 },
visible: { y: 0, opacity: 1 }
};
When a parent motion.ul switches from "hidden" to "visible", all motion.li children automatically animate their own "visible" states in sequence.
Key Takeaway: Variants let you define named animation states that orchestrate complex, coordinated animations across multiple components by simply changing one state value on a parent component.