
Table of Contents
Animations play a vital role in enhancing user experience by making web interactions more engaging and intuitive. However, implementing animations from scratch using CSS or JavaScript can be tedious, requiring significant effort to ensure smooth transitions and optimal performance. This is where Framer Motion simplifies the process.
Framer Motion is a powerful React-based animation library that allows developers to create fluid, high-performance animations with minimal effort. Whether you want to add subtle UI enhancements or complex motion sequences, Framer Motion provides an intuitive approach to integrating animations into web projects.
In this guide, we will explore practical Framer Motion examples, covering essential features like motion components, AnimatePresence, and layout animations—all with real-world applications to improve interactive web design.
1. Motion Component Usage
Motion components form the foundation of Framer Motion, allowing you to transform standard HTML elements into animated components effortlessly. Unlike traditional CSS animations, Framer Motion offers a more dynamic approach with fine-grained control over transitions, easing functions, and interactive triggers.
1.1 Understanding Motion Components
Framer Motion’s motion API extends basic elements like div, span, and button, enabling them to animate seamlessly. This removes the complexity of handling keyframes manually and ensures hardware-accelerated animations for better performance.
For example, instead of defining CSS transitions, you can animate an element with just a few lines of code:
<motion.div animate={{ opacity: 1, scale: 1.2 }} initial={{ opacity: 0, scale: 0.8 }} transition={{ duration: 0.5 }} />
This flexibility makes it easier to build engaging web animations that respond to user interactions. Additionally, optimised animations help retain visitors, considering that 53% of mobile users abandon a website that takes longer than three seconds to load. Ensuring animations are lightweight and efficient is crucial for performance.
1.2 Example: Animated Emoji Cards
A practical application of motion components is creating animated emoji cards. This Framer Motion example brings playful motion to UI elements, making them more visually engaging.
<motion.div className="card"
variants={cardVariants}>{emoji}</motion.div>
Such dynamic interactions are valuable for e-commerce websites and marketing landing pages, where motion effects can guide users toward key actions.
If you’re working on a Framer website, consider pairing Framer Motion with our high-performance Framer templates to enhance branding. Learn more in our Guide to Choosing the Right Framer Template for Your Startup.
2. AnimatePresence for Dynamic Lists
Managing animations for elements that enter or exit the DOM is often a challenge. AnimatePresence, a core feature of Framer Motion, ensures that disappearing elements animate smoothly instead of being removed abruptly. This is particularly useful for modals, notifications, and dynamic lists.
2.1 Exploring AnimatePresence
By default, React removes unmounted components immediately, leading to choppy transitions. AnimatePresence solves this by detecting component removal and allowing animations to complete before deletion.
For instance, when implementing tabbed navigation, removing a tab instantly can feel jarring. With AnimatePresence, you can apply smooth fade-out effects to inactive tabs, improving the flow of transitions.
<AnimatePresence>
{isVisible && (
<motion.div exit={{ opacity: 0, scale: 0.9 }} transition={{ duration: 0.3 }}>
Content here
</motion.div>
)}
</AnimatePresence>
This subtle improvement enhances user experience, making interactions feel more intuitive and polished.
2.2 Example: Dynamic Tabs Animation
Imagine an interactive dashboard where users switch between analytics reports. Instead of a sudden shift, animated tab transitions make navigation more seamless. Below is an example of tab animations using AnimatePresence:
<AnimatePresence mode="wait">
<motion.div key={selectedTab.label} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -20 }} transition={{ duration: 0.15 }}>
{selectedTab.icon}
</motion.div>
</AnimatePresence>
This technique is widely used in progressive web apps (PWAs) to enhance mobile responsiveness.
3. Layout Animations
Modern web applications rely on fluid layout shifts to improve responsiveness. Whether you’re designing a toggle switch, expanding a menu, or a reordering list, Framer Motion’s layout property allows components to animate their position changes smoothly.
3.1 The Layout Property
Traditional layout changes can feel abrupt, leading to a disjointed experience. Framer Motion’s layout prop automatically detects element size adjustments and animates them with a natural flow. This is especially beneficial for:
Interactive dashboards where charts resize dynamically
Navigation menus that expand or collapse smoothly
Form fields that adjust based on user input
<motion.div layout transition={{ type: "spring", stiffness: 500, damping: 30 }} />
This small addition creates a more polished user experience, keeping transitions sleek and lag-free.
3.2 Example: Toggle Switch Animation
Let’s take a common UI element—a toggle switch. Using Framer Motion’s layout prop, we can create an intuitive animation that smoothly shifts when toggled.
<div className="switch" data-isOn={isOn} onClick={toggleSwitch}>
<motion.div className="handle" layout transition={spring} />
</div>
Such micro-interactions improve user engagement, as they provide immediate feedback to actions.
If you’re optimising a Framer template for speed, you’ll also want to ensure animations don’t slow your site. Read Optimising Your Framer Template for Speed and Performance: Tips and Tricks.
4. Gesture Animations
Gesture animations create responsive and engaging user experiences by reacting to user actions like hovering, clicking, or dragging. These micro-interactions make web interfaces feel more intuitive and dynamic.
4.1 Handling Gestures in Framer Motion
Framer Motion provides gesture-based animations using properties like:
whileHover – Triggers effects when a user hovers over an element.
whileTap – Responds when an element is clicked or tapped.
drag – Enables elements to be moved interactively.
For instance, an interactive button can change its appearance based on user interaction, improving usability:
<motion.button whileHover={{ scale: 1.1 }} whileTap={{ scale: 0.9 }}>
Click Me
</motion.button>
4.2 Example: Interactive Button
A great use case for gesture animations is interactive buttons that respond to hover and tap interactions. Below is an example of a star rating button that reacts when hovered or clicked:
<motion.button
initial={false}
animate={[isLiked ? "liked" : "unliked", isHover ? "hover" : "rest"]}
whileTap="press"
variants={buttonVariants}
onHoverStart={() => setIsHover(true)}
onHoverEnd={() => setIsHover(false)}
onClick={() => setIsLiked(!isLiked)}
>
<motion.div className="icon" variants={{ liked: { opacity: 0 } }}>
<StarIcon isHover={isHover} isLiked={isLiked} />
</motion.div>
</motion.button>
This type of real-time feedback improves user interaction, making buttons more engaging and functional.
If you're customising Framer templates and want to improve UI interactivity, check out Customising Your Framer Template: A Guide for Beginners.
5. Advanced Transitions
Basic animations work well for simple effects, but for more dynamic interactions, Framer Motion allows fine-tuned transition control, such as spring physics, staggered animations, and animated numbers.
5.1 Creating Complex Transitions
Framer Motion’s transitions go beyond simple fade effects. It allows for spring-based movements, delayed animations, and custom bezier curves for smoother effects.
Key transition properties include:
spring – Creates realistic, physics-based motion.
easeInOut – Smoothens animations for a natural flow.
staggerChildren – Adds a cascading delay to multiple elements.
For example, a sequential loading animation can be achieved with:
<motion.div variants={{ hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.2 } } }}>
<motion.div variants={{ hidden: { y: 10 }, visible: { y: 0 } }} />
<motion.div variants={{ hidden: { y: 10 }, visible: { y: 0 } }} />
</motion.div>
5.2 Example: Animating Numerical Values
A common use case is animating counters or statistics, often seen in dashboards or progress indicators. If you're designing dashboards or analytic pages, don't miss our walkthrough on how to conduct a Framer performance audit.
const count = useMotionValue(0);
const rounded = useTransform(count, Math.round);
useEffect(() => {
animate(count, 100, { duration: 10 });
}, []);
return <motion.h1>{rounded}</motion.h1>;
By dynamically updating numeric values, this example creates a smooth counter animation, perfect for analytics dashboards or pricing displays.
6. Utilising Hooks in Framer Motion
Hooks provide additional flexibility in Framer Motion, enabling parallax effects, scroll-based animations, and dynamic transformations. These are crucial for smooth, modern web interactions.
6.1 Introduction to Framer Motion Hooks
Hooks allow developers to capture real-time motion values and dynamically adjust animations. Some essential Framer Motion hooks include:
useScroll – Triggers animations based on scroll position.
useSpring – Smoothens animations using spring physics.
useTransform – Maps one value to another, enabling responsive animations.
useVelocity – Adjusts animation speed dynamically.
6.2 Examples of Useful Hooks
6.2.1 useScroll for Parallax Effects
Parallax scrolling creates a depth effect, making backgrounds move slower than foreground elements:
const { scrollYProgress } = useScroll();
const yTransform = useTransform(scrollYProgress, [0, 1], [0, -200]);
return <motion.div style={{ y: yTransform }}>Parallax Content</motion.div>;
6.2.2 useSpring for Smooth Animations
Springs create natural motion curves without requiring manual timing adjustments.
const x = useMotionValue(0);
const springX = useSpring(x, { stiffness: 300, damping: 30 });
return <motion.div style={{ x: springX }} />;
6.2.3 useTransform for Responsive Animations
Transforms allow adaptive motion based on dynamic input values.
const scale = useTransform(scrollYProgress, [0, 1], [1, 1.5]);
return <motion.div style={{ scale }}>Scaling Effect</motion.div>;
6.2.4 useVelocity for Dynamic Speed Adjustments
By tracking scroll speed, useVelocity creates adaptive motion effects.
const scrollSpeed = useVelocity(scrollY);
const moveX = useTransform(scrollSpeed, [-1000, 1000], [-50, 50]);
return <motion.div style={{ x: moveX }}>Moving Element</motion.div>;
Framer Motion is a game-changer for web developers and designers looking to enhance UI with animations. Unlike traditional CSS animations, its motion components, AnimatePresence, and layout animations simplify the process while offering greater control. Whether you're creating gesture-based interactions, complex transitions, or scroll-driven effects, Framer Motion provides an intuitive way to build engaging and high-performance animations.
By leveraging motion hooks like useScroll and useSpring, you can create dynamic and responsive animations that not only improve aesthetics but also contribute to better user retention. Considering that 75% of users judge a company's credibility based on website design, investing in seamless animations is no longer optional—it's a necessity.
Need more help planning your website animations? Get the expert Framer guidance you need- just book a free consultation.
26 Sept 2024
Justica: Elevating Your Law Firm's Online Presence

Harish Malhi
26 Sept 2024
HairLoom Customization: Styling Your Beauty Business Website

Harish Malhi
25 Sept 2024
Designy Customization Mastery: Crafting Unique Design Agency Sites

Harish Malhi
25 Sept 2024
D-Next Features Explored: Customizing Your Event Website

Harish Malhi
25 Sept 2024
CryptoVault Customization: Tailoring Your Blockchain Platform

Harish Malhi
11 Jul 2024
The ROI of a Custom Job Board: How Bubble Can Boost Your Recruitment Efforts

Harish Malhi
21 Jun 2024
From Bubble to Reality: How to Implement a Seamless Payment Processing Solution for Your Marketplace

Harish Malhi
3 Jun 2024
How To Find The Best Bubble.io Developer for Hire ( Updated 2024)

Harish Malhi
10 Apr 2024
How to Export Content from WordPress to Framer: A Comprehensive Guide

Harish Malhi
13 Mar 2024
Elevate Your Design Blog with the HotelBlog Framer Template

Harish Malhi
13 Mar 2024
Streamline Your SaaS Documentation with the Doks Framer Template

Harish Malhi
13 Mar 2024
How Can a SEO Glossary Improve the Visibility of Your Content?

Harish Malhi
24 Aug 2023
Bubble.io Review: Pros and Cons of This No-code App Builder

Harish Malhi
17 Mar 2023
Maximising the Impact of AI on E-commerce Marketing

Harish Malhi
16 Mar 2023
Personalizing the Customer Experience with AI: Best Practices for Retailers

Harish Malhi
15 Mar 2023
How to Use AI in Real Estate: Strategies for Success using AI

Harish Malhi
29 Dec 2022
What Can You Build With Bubble?

Harish Malhi
29 Dec 2022
No-Code Experts Predict What Will Happen In 2023

Harish Malhi