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

Installing Framer Motion and Basic Setup

Add framer-motion to your project and understand the motion component wrapper pattern.

Installing Framer Motion and Basic Setup

You'll learn how to add Framer Motion to your React project and understand its core motion component wrapper pattern.

What Is Framer Motion?

Framer Motion is a production-ready animation library for React that solves the mount/unmount animation problem you just learned about. While CSS transitions can't animate components entering or leaving the DOM, Framer Motion handles this elegantly with a simple API.

Installation

Add Framer Motion to your project:

npm install framer-motion

Or with other package managers:

yarn add framer-motion
# or
pnpm add framer-motion

The motion Component Wrapper

Framer Motion's core concept is wrapping HTML elements with motion components. Think of motion as a special prefix that turns any standard HTML element into an animatable version:

import { motion } from 'framer-motion';

function Example() {
  return (
    <motion.div>
      This div can now animate!
    </motion.div>
  );
}

Every HTML element has a motion equivalent: motion.button, motion.span, motion.ul, etc. These components accept all normal HTML props plus animation props that Framer Motion provides.

Why This Pattern Matters

The wrapper pattern keeps your component structure familiar while unlocking animation capabilities. You're not learning a completely different way to write JSX—you're just replacing <div> with <motion.div> when you need animations. This makes adoption gradual and non-invasive.

Key Takeaway: Framer Motion installs via npm and uses a motion.element wrapper pattern that transforms standard HTML elements into animatable components without disrupting your existing component structure.