Initial State with initial Prop
What You'll Learn
You'll learn how to use the initial prop in Framer Motion to define where your animations begin, giving you complete control over the starting point of every animation.
The Core Idea
When you animate elements with Framer Motion's animate prop, they start from their default CSS values and transition to your target values. The initial prop lets you explicitly declare where the animation begins instead of relying on defaults. This is crucial when you want elements to fade in from transparent, slide in from off-screen, or start in any state different from their natural position.
Think of it like a theater stage: initial sets where the actor stands before the curtain opens, and animate directs where they move once the scene begins.
How It Works
The initial prop accepts the same property-value pairs as animate, but these values represent the starting state:
<motion.div
initial={{ opacity: 0, y: -50 }}
animate={{ opacity: 1, y: 0 }}
>
Hello!
</motion.div>
Here the element starts invisible (opacity: 0) and positioned 50 pixels above its natural location (y: -50). When it mounts, it animates to fully visible and its normal position.
Why It Matters
Without initial, elements appear instantly in their final state before animating—causing a visual "flash." Setting initial ensures smooth entrance animations every time, especially important for:
- Loading screens
- Page transitions
- Modal dialogs appearing
- List items entering view
Key Takeaway: The initial prop defines the starting values for your animations, ensuring elements begin exactly where you want them before transitioning to their animated state—eliminating visual flashes and creating polished entrance effects.