DEV Community

Arhan Khan
Arhan Khan

Posted on

Framer Motion for Beginners: Smooth Animations in React Without the Headaches

A website that moves well feels alive. Buttons that spring, cards that slide in, pages that fade — these small motions make an app feel polished. Framer Motion is a React animation library that makes all of this easy, with a simple API that reads almost like plain English.

The core idea is the motion component. Take any HTML element, add motion., and you can animate it with a few props:

import { motion } from 'framer-motion';

function WelcomeCard() {
  return (
    <motion.div
      initial={{ opacity: 0, y: 40 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.6, ease: 'easeOut' }}
    >
      <h1>Welcome back!</h1>
      <p>Your dashboard is ready.</p>
    </motion.div>
  );
}
Enter fullscreen mode Exit fullscreen mode

The card starts invisible and 40 pixels lower, then fades and slides into place over 0.6 seconds. That is the whole pattern: initial is where the animation starts, animate is where it ends, and transition controls how it gets there.

Framer Motion also handles the tricky parts. AnimatePresence lets components animate out when they leave the page — a modal that fades away instead of vanishing. Layout animations let a list reorder itself smoothly when items are added or removed. And gestures like drag, hover, and tap are built in:

<motion.button whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }}>
  Click me
</motion.button>
Enter fullscreen mode Exit fullscreen mode

That button grows slightly on hover and shrinks when pressed — a tiny detail that makes an interface feel responsive.

Framer Motion is for React developers who want their apps to feel polished without learning a complex animation system. Start with one fade-in on your main card, then add hover effects, then try page transitions. A little motion goes a long way.

Top comments (0)