Course contentsShow
← React
Lesson 1971 of 2,39645. AnimationsFree lesson

Animating on Mount and Unmount

Use initial and animate to create enter animations when components first render.

Animating on Mount and Unmount

You'll learn how to create smooth enter animations when components first appear using Framer Motion's declarative props.

The Core Idea

When a component renders for the first time, you want it to animate in from an initial state to its final position. You've already learned initial and animate separately—now you'll combine them to orchestrate mount animations. By setting initial to a hidden or offset state and animate to the visible state, Framer Motion automatically interpolates between them when the component first appears.

How It Works

Think of it like a theater curtain: initial is the closed curtain (before the show), and animate is the open curtain (the reveal). The transition between these states happens automatically on mount.

import { motion } from 'framer-motion';

function WelcomeMessage() {
  return (
    <motion.div
      initial={{ opacity: 0, y: -20 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.5 }}
    >
      Welcome back!
    </motion.div>
  );
}

When WelcomeMessage mounts, it starts invisible (opacity: 0) and slightly above its natural position (y: -20). Framer Motion then animates it to fully visible and in place over half a second.

Common Mount Animation Patterns

Fade in from above:

initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}

Scale up from center:

initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}

Slide in from left:

initial={{ opacity: 0, x: -50 }}
animate={{ opacity: 1, x: 0 }}

Key Takeaway: Combining initial and animate props creates automatic enter animations when components mount—Framer Motion handles the interpolation between these two states, giving you declarative control over how elements appear on screen.