Documentation

Documentation

Get started with Motion for React

Motion for React is a React animation library for building smooth, production-grade UI animations. You can start with simple prop-based animations before growing to layout, gesture and scroll animations.

Motion's unique hybrid engine combines the performance of native browser animations with the flexibility of JavaScript. It's also trusted by companies like Framer and Figma to power their amazing no-code animations and gestures.

In this guide, we'll learn why and when you should use Motion, how to install it, and then take a whirlwind tour of its main features.

Why Motion for React?

React gives you the power to build dynamic user interfaces, but orchestrating complex, performant animations can be a challenge. Motion is a production-ready library designed to solve this, making it simple to create everything from beautiful micro-interactions to complex, gesture-driven animations.

<motion.button animate={{ opacity: 1 }} />

Key advantages

Here’s when it’s the right choice for your project.

  • Built for React. While other animation libraries are messy to integrate, Motion's declarative API feels like a natural extension of React. Animations can be linked directly to state and props.

  • Hardware-acceleration. Motion leverages the same high-performance browser animations as pure CSS, ensuring your UIs stay smooth and snappy. You get the power of 120fps animations with a much simpler and more expressive API.

  • Animate anything. CSS has hard limits. There's values you can't animate, keyframes you can't interrupt, staggers that must be hardcoded. Motion provides a single, consistent API that handles everything from simple transitions to advanced scroll, layout, and gesture-driven effects.

  • App-like gestures. Standard CSS :hover events are unreliable on touch devices. Motion provides robust, cross-device gesture recognisers for tap, drag, and hover, making it easy to build interactions that feel native and intuitive on any device.

When is CSS a better choice?

For simple, self-contained effects (like a color change on hover) a standard CSS transition is a lightweight solution. The strength of Motion is that it can do these simple kinds of animations but also scale to anything you can imagine. All with the same easy to write and maintain API.

Install

Motion is available via npm:

npm install motion

Features can now be imported via "motion/react":

import { motion } from "motion/react"

Prefer to install via CDN, or looking for framework-specific instructions? Check out our full installation guide.

Your first animation

The <motion /> component is the core API in Motion for React. It's a DOM element, supercharged with animation capabilities.

<motion.ul animate={{ rotate: 360 }} />

When values in animate change, the component will animate. Motion has intuitive defaults, but animations can of course be configured via the transition prop.

<motion.div
  animate={{
    scale: 2,
    transition: { duration: 2 }
  }}
/>

Learn more about React animation

Enter animation

When a component enters the page, it will automatically animate to the values defined in the animate prop.

You can provide values to animate from via the initial prop (otherwise these will be read from the DOM).

<motion.button initial={{ scale: 0 }} animate={{ scale: 1 }} />

Or disable this initial animation entirely by setting initial to false.

<motion.button initial={false} animate={{ scale: 1 }} />

Hover & tap animation

<motion /> extends React's event system with powerful gesture animations. It currently supports hover, tap, focus, and drag.

<motion.button
  whileHover={{ scale: 1.1 }}
  whileTap={{ scale: 0.95 }}
  onHoverStart={() => console.log('hover started!')}
/>

Motion's gestures are designed to feel better than using CSS or JavaScript events alone.

Scroll animation

Motion supports both types of scroll animations: Scroll-triggered and scroll-linked.

To trigger an animation on scroll, the whileInView prop defines a state to animate to/from when an element enters/leaves the viewport:

<motion.div
  initial={{ backgroundColor: "rgb(0, 255, 0)", opacity: 0 }}
  whileInView={{ backgroundColor: "rgb(255, 0, 0)", opacity: 1 }}
/>

Whereas to link a value directly to scroll position, it's possible to use MotionValues via useScroll.

const { scrollYProgress } = useScroll()

return <motion.div style={{ scaleX: scrollYProgress }} />

Layout animation

Motion has an industry-leading layout animation engine that supports animating between changes in layout using transforms.

It's as easy as applying the layout prop.

<motion.div layout />

Or to animate between completely different elements, a layoutId:

<motion.div layoutId="underline" />

Exit animations

By wrapping motion components with <AnimatePresence> we gain access to exit animations. This allows us to animate elements as they're removed from the DOM.

<AnimatePresence>
  {show ? <motion.div key="box" exit={{ opacity: 0 }} /> : null}
</AnimatePresence>

Development tools

Motion provides developer tools to enhance your animation development experience, like loading your LLM with the latest Motion documentation, and visual bezier curve editors in VS Code.

Add to VS CodeAdd to Cursor

Learn next

That's a very quick overview of Motion for React's basic features. But there's a lot more to learn!

Next, we recommend starting with the React animation guide. Here, you'll learn more about the different types of animations you can build with Motion.

Or, you can learn by doing, diving straight into our collection of Fundamentals examples. Each comes complete with full source code that you can copy-paste into your project.

Motion for React is a React animation library for building smooth, production-grade UI animations. You can start with simple prop-based animations before growing to layout, gesture and scroll animations.

Motion's unique hybrid engine combines the performance of native browser animations with the flexibility of JavaScript. It's also trusted by companies like Framer and Figma to power their amazing no-code animations and gestures.

In this guide, we'll learn why and when you should use Motion, how to install it, and then take a whirlwind tour of its main features.

Why Motion for React?

React gives you the power to build dynamic user interfaces, but orchestrating complex, performant animations can be a challenge. Motion is a production-ready library designed to solve this, making it simple to create everything from beautiful micro-interactions to complex, gesture-driven animations.

<motion.button animate={{ opacity: 1 }} />

Key advantages

Here’s when it’s the right choice for your project.

  • Built for React. While other animation libraries are messy to integrate, Motion's declarative API feels like a natural extension of React. Animations can be linked directly to state and props.

  • Hardware-acceleration. Motion leverages the same high-performance browser animations as pure CSS, ensuring your UIs stay smooth and snappy. You get the power of 120fps animations with a much simpler and more expressive API.

  • Animate anything. CSS has hard limits. There's values you can't animate, keyframes you can't interrupt, staggers that must be hardcoded. Motion provides a single, consistent API that handles everything from simple transitions to advanced scroll, layout, and gesture-driven effects.

  • App-like gestures. Standard CSS :hover events are unreliable on touch devices. Motion provides robust, cross-device gesture recognisers for tap, drag, and hover, making it easy to build interactions that feel native and intuitive on any device.

When is CSS a better choice?

For simple, self-contained effects (like a color change on hover) a standard CSS transition is a lightweight solution. The strength of Motion is that it can do these simple kinds of animations but also scale to anything you can imagine. All with the same easy to write and maintain API.

Install

Motion is available via npm:

npm install motion

Features can now be imported via "motion/react":

import { motion } from "motion/react"

Prefer to install via CDN, or looking for framework-specific instructions? Check out our full installation guide.

Your first animation

The <motion /> component is the core API in Motion for React. It's a DOM element, supercharged with animation capabilities.

<motion.ul animate={{ rotate: 360 }} />

When values in animate change, the component will animate. Motion has intuitive defaults, but animations can of course be configured via the transition prop.

<motion.div
  animate={{
    scale: 2,
    transition: { duration: 2 }
  }}
/>

Learn more about React animation

Enter animation

When a component enters the page, it will automatically animate to the values defined in the animate prop.

You can provide values to animate from via the initial prop (otherwise these will be read from the DOM).

<motion.button initial={{ scale: 0 }} animate={{ scale: 1 }} />

Or disable this initial animation entirely by setting initial to false.

<motion.button initial={false} animate={{ scale: 1 }} />

Hover & tap animation

<motion /> extends React's event system with powerful gesture animations. It currently supports hover, tap, focus, and drag.

<motion.button
  whileHover={{ scale: 1.1 }}
  whileTap={{ scale: 0.95 }}
  onHoverStart={() => console.log('hover started!')}
/>

Motion's gestures are designed to feel better than using CSS or JavaScript events alone.

Scroll animation

Motion supports both types of scroll animations: Scroll-triggered and scroll-linked.

To trigger an animation on scroll, the whileInView prop defines a state to animate to/from when an element enters/leaves the viewport:

<motion.div
  initial={{ backgroundColor: "rgb(0, 255, 0)", opacity: 0 }}
  whileInView={{ backgroundColor: "rgb(255, 0, 0)", opacity: 1 }}
/>

Whereas to link a value directly to scroll position, it's possible to use MotionValues via useScroll.

const { scrollYProgress } = useScroll()

return <motion.div style={{ scaleX: scrollYProgress }} />

Layout animation

Motion has an industry-leading layout animation engine that supports animating between changes in layout using transforms.

It's as easy as applying the layout prop.

<motion.div layout />

Or to animate between completely different elements, a layoutId:

<motion.div layoutId="underline" />

Exit animations

By wrapping motion components with <AnimatePresence> we gain access to exit animations. This allows us to animate elements as they're removed from the DOM.

<AnimatePresence>
  {show ? <motion.div key="box" exit={{ opacity: 0 }} /> : null}
</AnimatePresence>

Development tools

Motion provides developer tools to enhance your animation development experience, like loading your LLM with the latest Motion documentation, and visual bezier curve editors in VS Code.

Add to VS CodeAdd to Cursor

Learn next

That's a very quick overview of Motion for React's basic features. But there's a lot more to learn!

Next, we recommend starting with the React animation guide. Here, you'll learn more about the different types of animations you can build with Motion.

Or, you can learn by doing, diving straight into our collection of Fundamentals examples. Each comes complete with full source code that you can copy-paste into your project.

Motion for React is a React animation library for building smooth, production-grade UI animations. You can start with simple prop-based animations before growing to layout, gesture and scroll animations.

Motion's unique hybrid engine combines the performance of native browser animations with the flexibility of JavaScript. It's also trusted by companies like Framer and Figma to power their amazing no-code animations and gestures.

In this guide, we'll learn why and when you should use Motion, how to install it, and then take a whirlwind tour of its main features.

Why Motion for React?

React gives you the power to build dynamic user interfaces, but orchestrating complex, performant animations can be a challenge. Motion is a production-ready library designed to solve this, making it simple to create everything from beautiful micro-interactions to complex, gesture-driven animations.

<motion.button animate={{ opacity: 1 }} />

Key advantages

Here’s when it’s the right choice for your project.

  • Built for React. While other animation libraries are messy to integrate, Motion's declarative API feels like a natural extension of React. Animations can be linked directly to state and props.

  • Hardware-acceleration. Motion leverages the same high-performance browser animations as pure CSS, ensuring your UIs stay smooth and snappy. You get the power of 120fps animations with a much simpler and more expressive API.

  • Animate anything. CSS has hard limits. There's values you can't animate, keyframes you can't interrupt, staggers that must be hardcoded. Motion provides a single, consistent API that handles everything from simple transitions to advanced scroll, layout, and gesture-driven effects.

  • App-like gestures. Standard CSS :hover events are unreliable on touch devices. Motion provides robust, cross-device gesture recognisers for tap, drag, and hover, making it easy to build interactions that feel native and intuitive on any device.

When is CSS a better choice?

For simple, self-contained effects (like a color change on hover) a standard CSS transition is a lightweight solution. The strength of Motion is that it can do these simple kinds of animations but also scale to anything you can imagine. All with the same easy to write and maintain API.

Install

Motion is available via npm:

npm install motion

Features can now be imported via "motion/react":

import { motion } from "motion/react"

Prefer to install via CDN, or looking for framework-specific instructions? Check out our full installation guide.

Your first animation

The <motion /> component is the core API in Motion for React. It's a DOM element, supercharged with animation capabilities.

<motion.ul animate={{ rotate: 360 }} />

When values in animate change, the component will animate. Motion has intuitive defaults, but animations can of course be configured via the transition prop.

<motion.div
  animate={{
    scale: 2,
    transition: { duration: 2 }
  }}
/>

Learn more about React animation

Enter animation

When a component enters the page, it will automatically animate to the values defined in the animate prop.

You can provide values to animate from via the initial prop (otherwise these will be read from the DOM).

<motion.button initial={{ scale: 0 }} animate={{ scale: 1 }} />

Or disable this initial animation entirely by setting initial to false.

<motion.button initial={false} animate={{ scale: 1 }} />

Hover & tap animation

<motion /> extends React's event system with powerful gesture animations. It currently supports hover, tap, focus, and drag.

<motion.button
  whileHover={{ scale: 1.1 }}
  whileTap={{ scale: 0.95 }}
  onHoverStart={() => console.log('hover started!')}
/>

Motion's gestures are designed to feel better than using CSS or JavaScript events alone.

Scroll animation

Motion supports both types of scroll animations: Scroll-triggered and scroll-linked.

To trigger an animation on scroll, the whileInView prop defines a state to animate to/from when an element enters/leaves the viewport:

<motion.div
  initial={{ backgroundColor: "rgb(0, 255, 0)", opacity: 0 }}
  whileInView={{ backgroundColor: "rgb(255, 0, 0)", opacity: 1 }}
/>

Whereas to link a value directly to scroll position, it's possible to use MotionValues via useScroll.

const { scrollYProgress } = useScroll()

return <motion.div style={{ scaleX: scrollYProgress }} />

Layout animation

Motion has an industry-leading layout animation engine that supports animating between changes in layout using transforms.

It's as easy as applying the layout prop.

<motion.div layout />

Or to animate between completely different elements, a layoutId:

<motion.div layoutId="underline" />

Exit animations

By wrapping motion components with <AnimatePresence> we gain access to exit animations. This allows us to animate elements as they're removed from the DOM.

<AnimatePresence>
  {show ? <motion.div key="box" exit={{ opacity: 0 }} /> : null}
</AnimatePresence>

Development tools

Motion provides developer tools to enhance your animation development experience, like loading your LLM with the latest Motion documentation, and visual bezier curve editors in VS Code.

Add to VS CodeAdd to Cursor

Learn next

That's a very quick overview of Motion for React's basic features. But there's a lot more to learn!

Next, we recommend starting with the React animation guide. Here, you'll learn more about the different types of animations you can build with Motion.

Or, you can learn by doing, diving straight into our collection of Fundamentals examples. Each comes complete with full source code that you can copy-paste into your project.

Related topics

Motion is supported by the best in the industry.

Stay in the loop

Subscribe for the latest news & updates.

Stay in the loop

Subscribe for the latest news & updates.