Course contentsShow
← Web Development
Lesson 2561 of 2,98246. Animation LibrariesFree lesson

Installing and Setting Up Framer Motion

Install Framer Motion in a React project and understand its core philosophy of declarative animations.

Installing and Setting Up Framer Motion

You'll learn how to add Framer Motion to your React project and understand its declarative approach to animation.

What Is Framer Motion?

Framer Motion is a production-ready animation library built specifically for React. Unlike GSAP (which works with any JavaScript project), Framer Motion embraces React's component model completely. Think of it as "animations as JSX props" — instead of imperatively calling animation methods, you declare what animated state you want, and Framer Motion handles the transitions automatically.

Installing Framer Motion

Add Framer Motion to your React project via npm or yarn:

npm install framer-motion

or

yarn add framer-motion

That's it! No additional setup files or configuration needed.

Basic Import Pattern

Once installed, import the motion component wrapper:

import { motion } from 'framer-motion';

The motion object provides animated versions of HTML elements. Instead of writing <div>, you write <motion.div> and gain access to animation props.

The Declarative Philosophy

Here's where Framer Motion differs from GSAP: you don't write "animate this element to x=100 over 2 seconds." Instead, you declare states like animate={{ x: 100 }} directly on your component. Framer Motion detects when these props change and automatically animates between states. It's reactive by design, fitting naturally into React's data-driven rendering model.

This approach means animations live alongside your component logic, not in separate timeline files or useEffect hooks.

Key Takeaway: Framer Motion installs with a single npm command and follows a declarative pattern where you specify what to animate as component props, not how to animate imperatively — making it feel like native React.