Orchestrating Child Animations with Variants
You'll learn how to propagate variant names to child motion components, enabling coordinated stagger and sequence effects across multiple elements without managing each animation individually.
The Core Idea
So far, you've defined variants on individual components to switch between animation states. But Framer Motion has a powerful feature: when a parent motion component changes to a variant, all child motion components automatically receive that same variant name. This lets you define coordinated animations across an entire tree of elements declaratively.
Think of it like a conductor raising their baton: all musicians (child components) know to respond to the same signal (variant name), but each can interpret it differently based on their own variant definitions.
How It Works
Define variants on both parent and children. When the parent's animate prop changes to a variant name, children automatically animate to their version of that same variant:
const listVariants = {
hidden: { opacity: 0 },
visible: {
opacity: 1,
transition: { staggerChildren: 0.1 }
}
};
const itemVariants = {
hidden: { opacity: 0, x: -20 },
visible: { opacity: 1, x: 0 }
};
function List() {
return (
<motion.ul
variants={listVariants}
initial="hidden"
animate="visible"
>
<motion.li variants={itemVariants}>Item 1</motion.li>
<motion.li variants={itemVariants}>Item 2</motion.li>
<motion.li variants={itemVariants}>Item 3</motion.li>
</motion.ul>
);
}
Notice staggerChildren in the parent's visible variant—this delays each child's animation by 0.1 seconds, creating a cascading effect. Children don't need individual animate props; they inherit the variant name from their parent.
Key Takeaway: Propagating variant names from parent to children enables coordinated, staggered animations across component trees without manual timing management—the parent controls the orchestration, while each child defines its own response to the same variant signal.