Bring Your UI To Life
Master the art of animation and micro-interactions to create engaging, delightful user experiences
Step-by-Step Implementation
Tutorial Sections
Framer Motion Fundamentals
Master the basics of Framer Motion animations and setup
Installation and Setup
5 minFramer Motion is the most popular animation library for React with a declarative API.
Why Framer Motion?
- Declarative syntax
- Gesture support
- Layout animations
- SVG animations
- Physics-based animations
Installation:
Install Framer Motion in your Next.js project
// Install Framer Motion
npm install framer-motion
// Basic setup in layout or component
import { motion } from 'framer-motion';
export default function App() {
return (
<div>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.5 }}
>
Welcome to animations!
</motion.div>
</div>
);
}
// TypeScript support (included by default)
interface AnimationProps {
children: React.ReactNode;
delay?: number;
}
const AnimatedComponent: React.FC<AnimationProps> = ({
children,
delay = 0
}) => {
return (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay, duration: 0.6 }}
>
{children}
</motion.div>
);
};Basic Animation Properties
10 minCore Animation Props:
- initial: Starting state
- animate: End state
- exit: Animation when component unmounts
- transition: Controls timing and easing
Transform Properties:
- x, y, z (translate)
- scale, scaleX, scaleY
- rotate, rotateX, rotateY, rotateZ
- opacity
Best Practice: Use transform properties for smooth animations.
// Basic animations
<motion.div
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.8 }}
transition={{
duration: 0.5,
ease: "easeOut"
}}
>
Fade and scale animation
</motion.div>
// Slide animations
<motion.div
initial={{ x: -100, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
transition={{
type: "spring",
stiffness: 100,
damping: 15
}}
>
Slide in from left
</motion.div>
// Rotation with color change
<motion.div
initial={{
rotate: 0,
backgroundColor: "#ff0000"
}}
animate={{
rotate: 360,
backgroundColor: "#0066ff"
}}
transition={{
duration: 2,
repeat: Infinity,
repeatType: "reverse"
}}
className="w-20 h-20 rounded-lg"
/>
// Complex keyframes
<motion.div
animate={{
scale: [1, 2, 2, 1, 1],
rotate: [0, 0, 270, 270, 0],
borderRadius: ["20%", "20%", "50%", "50%", "20%"],
}}
transition={{
duration: 2,
ease: "easeInOut",
times: [0, 0.2, 0.5, 0.8, 1],
repeat: Infinity,
repeatDelay: 1
}}
/>Animation Variants
10 minVariants allow you to define named animation states and create complex orchestrated animations.
Benefits:
- Cleaner code
- Reusable animations
- Easy orchestration
- Dynamic animations
Variant Propagation: Parent variants automatically propagate to children.
// Define animation variants
const containerVariants = {
hidden: {
opacity: 0,
scale: 0.8
},
visible: {
opacity: 1,
scale: 1,
transition: {
duration: 0.5,
staggerChildren: 0.1,
delayChildren: 0.2
}
},
exit: {
opacity: 0,
scale: 0.8,
transition: {
duration: 0.3
}
}
};
const itemVariants = {
hidden: {
y: 20,
opacity: 0
},
visible: {
y: 0,
opacity: 1,
transition: {
type: "spring",
stiffness: 100
}
}
};
// Using variants in components
function AnimatedList({ items }) {
return (
<motion.ul
variants={containerVariants}
initial="hidden"
animate="visible"
exit="exit"
className="space-y-4"
>
{items.map((item, index) => (
<motion.li
key={item.id}
variants={itemVariants}
className="p-4 bg-white rounded-lg shadow"
>
{item.title}
</motion.li>
))}
</motion.ul>
);
}
// Dynamic variants
const buttonVariants = {
idle: { scale: 1 },
hover: {
scale: 1.05,
boxShadow: "0 10px 25px rgba(0,0,0,0.1)"
},
tap: { scale: 0.95 },
loading: {
scale: [1, 1.1, 1],
transition: {
repeat: Infinity,
duration: 1.5
}
}
};
function AnimatedButton({ isLoading, children, onClick }) {
return (
<motion.button
variants={buttonVariants}
initial="idle"
whileHover="hover"
whileTap="tap"
animate={isLoading ? "loading" : "idle"}
onClick={onClick}
className="px-6 py-3 bg-blue-500 text-white rounded-lg"
>
{children}
</motion.button>
);
}Types of Animations
Page Transitions
BeginnerSmooth transitions between pages and routes
Fade in/out, slide, scale effects
Hover Effects
BeginnerInteractive animations on user hover
Button states, card lifts, color transitions
Loading States
IntermediateEngaging loading animations and skeletons
Spinners, progress bars, skeleton screens
Micro-interactions
IntermediateSmall animations that enhance UX
Button clicks, form validation, notifications
Complex Animations
AdvancedAdvanced animated sequences and physics
Parallax, morphing, physics-based animations
Animation Libraries & Tools
Framer Motion
Production-ready motion library for React
React Spring
Spring-physics based animations
Lottie React
Render After Effects animations
CSS Animations
Native CSS transitions and keyframes
Code Examples
Basic Fade Animation
Simple fade in effect with Framer Motion
import { motion } from 'framer-motion';
export default function FadeIn({ children }) {
return (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.6 }}
>
{children}
</motion.div>
);
}Animation Best Practices
Respect User Preferences
Honor prefers-reduced-motion for accessibility
Keep It Subtle
Animations should enhance, not distract
Optimize Performance
Use transform and opacity for smooth animations
Meaningful Motion
Every animation should have a purpose
Try It Yourself
Interactive Animation Playground
Experiment with different animation properties and see the results in real-time
Ready to Animate?
Start creating delightful user experiences with smooth animations
Enhanced Learning Experience
Interactive Examples - Try Them Out!
Interactive Features
- • Live Preview: Click "Show Preview" to see animations in real-time
- • Edit & Experiment: Modify the code and see instant updates
- • Copy Code: Use the copy button to grab code for your projects
- • Open in Sandbox: Launch in CodeSandbox for full development environment