Skip to main content
Motion is a simple yet powerful animation library for JavaScript and React. This guide will help you create your first animation.

Installation

1

Install Motion

npm install motion
2

Import Motion

import { motion } from "motion/react"
3

Create your first animation

Add the animate prop to a motion component to animate it on mount:
function App() {
  return (
    <motion.div
      animate={{ x: 100 }}
      style={{ width: 100, height: 100, background: "#0077ff" }}
    />
  )
}
The motion.div will slide 100 pixels to the right when it appears.

Add interactivity

Make your animations interactive with hover effects and springs.
Use whileHover to animate on hover, and add a spring transition for natural motion:
function App() {
  return (
    <motion.div
      whileHover={{ scale: 1.2 }}
      transition={{ type: "spring", bounce: 0.4 }}
      style={{ 
        width: 100, 
        height: 100, 
        background: "#0077ff",
        borderRadius: 10
      }}
    />
  )
}
The box will spring and scale up when you hover over it.

Control animations with state

Animate based on component state:
import { motion } from "motion/react"
import { useState } from "react"

function App() {
  const [isActive, setIsActive] = useState(false)

  return (
    <motion.div
      animate={{ x: isActive ? 200 : 0 }}
      transition={{ duration: 0.4 }}
      onClick={() => setIsActive(!isActive)}
      style={{ 
        width: 100, 
        height: 100, 
        background: "#0077ff",
        cursor: "pointer"
      }}
    />
  )
}
Click the box to toggle its position.

Next steps

Animation API

Explore Motion’s animation capabilities

Gestures

Add drag, hover, and tap interactions

Spring Physics

Create natural, physics-based animations

Examples

Browse 100+ animation examples

Build docs developers (and LLMs) love