← All articles

Web Development · 5 November 2026 · 11 min read

Adding Smooth Animations to Next.js with Motion (Formerly Framer Motion)

Learn how to integrate Motion into a Next.js application and create smooth object animations, text reveals, hover interactions, staggered effects, and scroll-triggered animations using React.

  • Next.js
  • React
  • Motion
  • Framer Motion
  • Frontend Development
  • Web Animations
Adding Smooth Animations to Next.js with Motion (Formerly Framer Motion)

Adding Smooth Animations to Next.js with Motion (Formerly Framer Motion)

A well-designed website is not just about its layout, typography, or color palette. Small interactions and animations can make an interface feel more responsive, intuitive, and engaging.

When building applications with Next.js, we can use CSS transitions for simple interactions. However, when animations involve multiple elements, coordinated transitions, scroll-based effects, or dynamic UI states, managing everything manually can become difficult.

This is where Motion for React, previously known as Framer Motion, becomes useful.

Motion provides a declarative animation API that integrates naturally with React components. Instead of writing complicated animation logic, we can describe how an element should look initially, how it should change, and how that transition should happen.

In this tutorial, we'll explore how to integrate Motion into a Next.js application and implement some practical animations:

  • Basic object animations.
  • Hover and tap interactions.
  • Text entrance animations.
  • Staggered animations for multiple elements.
  • Scroll-triggered reveal animations.
  • Scroll progress indicators.
  • Reusable animation components.

1. Understanding Motion for React

Motion is an animation library for React, JavaScript, and Vue.

Previously, the React library was known as Framer Motion. It is now distributed as the motion package, with React APIs imported from motion/react.

The library provides several useful capabilities:

Feature Purpose
animate Animate an element between states
initial Define the initial animation state
whileHover Animate on mouse hover
whileTap Animate during a press interaction
whileInView Trigger animations when elements enter the viewport
variants Reuse and coordinate animation states
useScroll Track scroll position and progress
AnimatePresence Animate elements when they leave the DOM
layout Animate layout changes

One of the reasons I find this API interesting is its declarative approach. We describe the desired animation rather than manually calculating every frame.

2. Installing Motion in Next.js

First, create a Next.js application if you don't already have one.

bun create next-app my-motion-project
cd my-motion-project

Install Motion:

bun add motion

You can also use npm:

npm install motion

Once installed, import Motion components using:

import { motion } from "motion/react";

Understanding Next.js Client Components

This is an important detail when working with Motion and the Next.js App Router.

Next.js uses React Server Components by default. Interactive animation components that use client-side hooks or browser interactions should be implemented as Client Components.

Add the "use client" directive at the beginning of the component:

"use client";
 
import { motion } from "motion/react";
 
export default function AnimatedComponent() {
  return <motion.div animate={{ opacity: 1 }}>Hello Motion!</motion.div>;
}

There is also another option: Motion provides motion/react-client for using Motion components in React Server Component environments without converting the entire component into a Client Component.

import * as motion from "motion/react-client";
 
export default function AnimatedComponent() {
  return <motion.div animate={{ opacity: 1 }}>Hello Motion!</motion.div>;
}

For interactive examples involving hooks such as useScroll, we'll use Client Components.

This separation helps avoid unnecessarily converting entire pages into client-rendered components.

3. Understanding the Basic Animation Structure

Before building more complex animations, let's understand the three most important properties:

  • initial: The starting state of an element.
  • animate: The state to which the element should animate.
  • transition: Controls the timing and behavior of the animation.

Consider a simple example:

"use client";
 
import { motion } from "motion/react";
 
export default function BasicAnimation() {
  return (
    <motion.div
      initial={{ opacity: 0, y: 30 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.6 }}
      className="rounded-xl bg-blue-600 p-8 text-white"
    >
      Welcome to Motion!
    </motion.div>
  );
}

Let's understand what happens here.

  1. Initially, the element is transparent.
  2. It starts 30 pixels below its final position.
  3. Its opacity transitions to 1.
  4. Its vertical position transitions to 0.
  5. The transition takes 0.6 seconds.

The result is a simple fade-in and upward movement.

This combination is particularly useful for hero sections, cards, headings, and other elements that should appear when a page loads.

4. Creating Simple Object Animations

Let's explore some common animations that can be applied to interface elements.

4.1 Fade and slide animation

This is one of the most commonly used entrance animations.

"use client";
 
import { motion } from "motion/react";
 
export default function FadeSlide() {
  return (
    <motion.div
      initial={{ opacity: 0, y: 40 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{
        duration: 0.7,
        ease: "easeOut",
      }}
      className="rounded-2xl bg-zinc-900 p-10 text-white"
    >
      <h2 className="text-2xl font-bold">Build something amazing.</h2>
      <p className="mt-3 text-zinc-400">Smooth animations with Motion.</p>
    </motion.div>
  );
}

You can adjust the y value to control how far the element travels.

4.2 Scale animation

Scale animations are useful for creating subtle entrance effects.

<motion.div
  initial={{ opacity: 0, scale: 0.8 }}
  animate={{ opacity: 1, scale: 1 }}
  transition={{ duration: 0.5 }}
  className="h-32 w-32 rounded-2xl bg-purple-600"
/>

The element starts at 80% of its original size and scales to its normal dimensions.

4.3 Hover and tap animations

Motion also provides gesture-based animations.

For example, we can make a card slightly enlarge when hovered.

<motion.div
  whileHover={{ scale: 1.05 }}
  whileTap={{ scale: 0.95 }}
  transition={{ duration: 0.2 }}
  className="cursor-pointer rounded-xl bg-white p-8 shadow-lg"
>
  <h2 className="text-xl font-semibold">Hover over me</h2>
</motion.div>

Here:

  • whileHover activates when the pointer hovers over the element.
  • whileTap activates while the element is pressed.
  • transition controls how quickly the interaction happens.

These animations are useful for buttons, cards, navigation links, and interactive elements.

5. Animating Text with Motion

Text animations are particularly useful in hero sections, landing pages, and personal portfolios.

Instead of displaying all text immediately, we can animate its entrance.

5.1 Simple heading animation

"use client";
 
import { motion } from "motion/react";
 
export default function AnimatedHeading() {
  return (
    <motion.h1
      initial={{ opacity: 0, y: 40 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{
        duration: 0.8,
        ease: "easeOut",
      }}
      className="text-5xl font-bold"
    >
      Building the future with code.
    </motion.h1>
  );
}

This creates a smooth upward reveal effect.

5.2 Animating individual words

We can take this further by animating individual words with a staggered effect.

First, define animation variants:

const containerVariants = {
  hidden: {},
  visible: {
    transition: {
      staggerChildren: 0.12,
    },
  },
};
 
const wordVariants = {
  hidden: {
    opacity: 0,
    y: 30,
  },
  visible: {
    opacity: 1,
    y: 0,
    transition: {
      duration: 0.5,
      ease: "easeOut" as const,
    },
  },
};

Now create the animated heading:

"use client";
 
import { motion } from "motion/react";
 
const words = ["Building", "modern", "web", "experiences."];
 
const containerVariants = {
  hidden: {},
  visible: {
    transition: {
      staggerChildren: 0.12,
    },
  },
};
 
const wordVariants = {
  hidden: { opacity: 0, y: 30 },
  visible: {
    opacity: 1,
    y: 0,
    transition: {
      duration: 0.5,
      ease: "easeOut" as const,
    },
  },
};
 
export default function WordAnimation() {
  return (
    <motion.h1
      variants={containerVariants}
      initial="hidden"
      animate="visible"
      className="flex flex-wrap gap-x-3 text-5xl font-bold"
    >
      {words.map((word, index) => (
        <motion.span key={index} variants={wordVariants}>
          {word}
        </motion.span>
      ))}
    </motion.h1>
  );
}

Notice the staggerChildren property.

It controls the delay between the animation of individual child elements.

Instead of animating every word simultaneously, each word appears after the previous one.

This technique is particularly effective for hero headings and short introductory statements.

6. Creating Staggered Animations for Multiple Objects

Staggered animations are not limited to text.

We can use the same approach to animate multiple cards, images, or other components.

Imagine a portfolio section containing three project cards.

We want each card to appear sequentially rather than all at once.

First, define the variants:

const containerVariants = {
  hidden: {},
  visible: {
    transition: {
      staggerChildren: 0.2,
    },
  },
};
 
const cardVariants = {
  hidden: {
    opacity: 0,
    y: 40,
  },
  visible: {
    opacity: 1,
    y: 0,
    transition: {
      duration: 0.6,
    },
  },
};

Then apply them to the project cards:

"use client";
 
import { motion } from "motion/react";
 
const projects = [
  "AI Dashboard",
  "Portfolio Website",
  "Object Detection System",
];
 
export default function ProjectSection() {
  return (
    <motion.div
      variants={containerVariants}
      initial="hidden"
      whileInView="visible"
      viewport={{ once: true, amount: 0.2 }}
      className="grid gap-6 md:grid-cols-3"
    >
      {projects.map((project) => (
        <motion.div
          key={project}
          variants={cardVariants}
          className="rounded-xl bg-zinc-900 p-8 text-white"
        >
          <h3 className="text-xl font-semibold">{project}</h3>
        </motion.div>
      ))}
    </motion.div>
  );
}

Each card appears with a slight delay.

The important difference here is the use of whileInView instead of animate.

This means the animation starts when the component enters the viewport.

7. Implementing Scroll Animations

Scroll animations are useful when building long landing pages, portfolios, blogs, and product websites.

Motion provides two different approaches:

Scroll-triggered animations: An animation starts when an element enters or leaves the viewport.

Scroll-linked animations: An animation is directly connected to the user's scroll position.

Let's implement both.

7.1 Scroll-triggered reveal animation

The whileInView property is one of the simplest ways to create scroll animations.

"use client";
 
import { motion } from "motion/react";
 
export default function ScrollReveal() {
  return (
    <motion.section
      initial={{ opacity: 0, y: 60 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true, amount: 0.2 }}
      transition={{
        duration: 0.7,
        ease: "easeOut",
      }}
      className="py-32"
    >
      <h2 className="text-4xl font-bold">Discover what we build.</h2>
 
      <p className="mt-4 text-zinc-500">
        This section appears when you scroll down.
      </p>
    </motion.section>
  );
}

Let's understand the viewport configuration:

viewport={{
  once: true,
  amount: 0.2,
}}
  • once: true means the animation runs only the first time the element enters the viewport.
  • amount: 0.2 means approximately 20% of the element must enter the viewport to trigger the animation.

You can use this pattern for almost any section of a website.

7.2 Creating a scroll progress indicator

Another useful animation is a progress bar that follows the user's scrolling position.

For example, a blog website can display a thin progress indicator at the top of the screen to show how much of an article has been read.

Motion provides the useScroll hook for this purpose.

"use client";
 
import { motion, useScroll } from "motion/react";
 
export default function ScrollProgress() {
  const { scrollYProgress } = useScroll();
 
  return (
    <motion.div
      className="fixed left-0 top-0 z-50 h-1 w-full origin-left bg-blue-600"
      style={{
        scaleX: scrollYProgress,
      }}
    />
  );
}

The useScroll() hook returns Motion Values representing the current scroll position and scroll progress.

scrollYProgress ranges from 0 to 1.

  • 0 means the page is at the beginning.
  • 0.5 means approximately halfway through the scrollable page.
  • 1 means the bottom has been reached.

By connecting this value to scaleX, we can create a progress bar that grows as the user scrolls.

7.3 Creating a parallax effect

Parallax animation creates a sense of depth by moving visual elements at different speeds as the user scrolls.

We can use useScroll and useTransform together.

"use client";
 
import { motion, useScroll, useTransform } from "motion/react";
 
export default function ParallaxSection() {
  const { scrollYProgress } = useScroll();
 
  const y = useTransform(scrollYProgress, [0, 1], [0, -200]);
 
  return (
    <section className="relative flex h-screen items-center justify-center overflow-hidden">
      <motion.div
        style={{ y }}
        className="rounded-3xl bg-purple-600 p-20 text-white"
      >
        <h2 className="text-5xl font-bold">Explore beyond limits.</h2>
      </motion.div>
    </section>
  );
}

Here, useTransform maps the scroll progress to a vertical movement.

As the user scrolls, the element moves upward.

You can experiment with different ranges to create more subtle effects.

For more complex parallax effects, consider tracking individual elements with the target option of useScroll.

8. Creating Reusable Animation Components

When building larger Next.js applications, writing the same animation configuration repeatedly can make components difficult to maintain.

A better approach is to create reusable animation components.

For example, create:

components/animations/Reveal.tsx

"use client";
 
import { motion, type Variants } from "motion/react";
import type { ReactNode } from "react";
 
interface RevealProps {
  children: ReactNode;
  delay?: number;
  className?: string;
}
 
export default function Reveal({
  children,
  delay = 0,
  className,
}: RevealProps) {
  const variants: Variants = {
    hidden: {
      opacity: 0,
      y: 40,
    },
    visible: {
      opacity: 1,
      y: 0,
      transition: {
        duration: 0.6,
        delay,
        ease: "easeOut",
      },
    },
  };
 
  return (
    <motion.div
      variants={variants}
      initial="hidden"
      whileInView="visible"
      viewport={{ once: true, amount: 0.2 }}
      className={className}
    >
      {children}
    </motion.div>
  );
}

Now we can reuse the component throughout our application.

import Reveal from "@/components/animations/Reveal";
 
export default function Home() {
  return (
    <main>
      <Reveal>
        <h1 className="text-5xl font-bold">Welcome to my portfolio.</h1>
      </Reveal>
 
      <Reveal delay={0.2}>
        <p className="mt-6">I build applications using modern technologies.</p>
      </Reveal>
 
      <Reveal delay={0.4}>
        <button className="mt-8 rounded-lg bg-blue-600 px-6 py-3 text-white">
          Explore Projects
        </button>
      </Reveal>
    </main>
  );
}

This keeps animation logic separate from page content and makes it easier to maintain a consistent animation style.

9. Performance and Accessibility Considerations

Animations should improve the user experience rather than make the website difficult to use.

There are a few important considerations.

Prefer transform and opacity

Whenever possible, animate properties such as:

  • opacity
  • transform
  • scale
  • x
  • y

These properties are generally more efficient to animate than properties that trigger repeated layout calculations, such as width, height, and top.

Avoid excessive animations

Not every element needs an animation.

Too many simultaneous animations can make a website feel distracting and may affect performance, particularly on lower-powered devices.

Use animation to establish visual hierarchy and guide attention.

Respect reduced-motion preferences

Some users prefer reduced motion because of accessibility needs.

Motion provides the useReducedMotion hook to detect the user's reduced-motion preference.

For example:

"use client";
 
import { motion, useReducedMotion } from "motion/react";
 
export default function AccessibleAnimation() {
  const shouldReduceMotion = useReducedMotion();
 
  return (
    <motion.div
      initial={{
        opacity: 0,
        y: shouldReduceMotion ? 0 : 30,
      }}
      animate={{
        opacity: 1,
        y: 0,
      }}
      transition={{ duration: shouldReduceMotion ? 0 : 0.6 }}
    >
      Accessible animations matter.
    </motion.div>
  );
}

This example removes the movement when reduced motion is requested while preserving the basic appearance transition.

10. When Should You Use Motion Instead of CSS?

Motion is not necessarily the best choice for every animation.

CSS transitions are often sufficient for simple hover effects, color changes, and small visual transitions.

Motion becomes more useful when animations involve:

  • Multiple coordinated components.
  • Dynamic React state.
  • Staggered entrance effects.
  • Scroll-triggered animations.
  • Parallax effects.
  • Layout transitions.
  • Interactive gestures.

A practical approach is to use CSS for simple styling interactions and Motion when the animation logic benefits from React integration.

Conclusion

Motion makes it easier to build expressive and interactive interfaces in Next.js without manually managing complex animation logic.

Starting with basic fade and slide animations, we can gradually introduce staggered text effects, hover interactions, scroll-triggered reveals, and scroll-linked animations.

The most useful takeaway is that animations should have a purpose. A subtle entrance animation can guide attention, a hover effect can communicate interactivity, and a scroll progress indicator can improve navigation.

Start with a few small animations, understand how initial, animate, variants, and whileInView work, and then build reusable components for your application.

The goal is not to animate everything. It is to make the interface feel natural and responsive.


References

  1. Motion for React – Official Documentation
  2. Motion Installation Guide – Next.js
  3. Motion Component API
  4. Scroll Animations
  5. useScroll Hook
  6. Motion Upgrade Guide – Framer Motion to Motion
  7. Motion Accessibility Guide
AS

Aditya Manoj Shinde

Author

I'm Aditya, a developer passionate about AI, Machine Learning, and software development. I love exploring new technologies, building projects, and sharing what I learn along the way.