Framer Motion Motion Animation Library

Last updated: 2026-11-02

Framer Motion Motion Animation Library

Framer Motion (published today as the motion package) is the most popular animation library for React: declare the initial state, the target state and the transition on a motion.div and it tweens between them for you. AnimatePresence handles exit animations, and gestures plus layout animations are supported out of the box, which makes the library a natural fit for state-driven interfaces.

GroupEcosystem
KindLibrary
Sincev11 (official package name motion, imported from motion/react)

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

npm install motion

import { motion, AnimatePresence } from 'motion/react'

<motion.div
  initial={{ opacity: 0, y: -20 }}               // initial state
  animate={{ opacity: 1, y: 0 }}                 // target state
  exit={{ opacity: 0 }}                          // exit state (needs AnimatePresence)
  transition={{ duration: 0.3, ease: 'easeOut' }} // transition config
>
  Content
</motion.div>

// Spring physics: <motion.button whileTap={{ scale: 0.9 }} />

⚙️ Parameters

initial / animateThe starting and target style objects; the library tweens between them whenever a value changes.
transitionTransition configuration: duration, easing curve, or spring physics parameters (type: 'spring', stiffness, damping).
AnimatePresenceWraps conditionally rendered elements so the exit animation plays before the component is removed from the DOM.

Returns:No return value — see the example for third-party library usage.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

Simulation: after clicking Open modal the mask fades in over 0.3s and the panel springs from a shrunken state above into the center of the screen (spring-like easing); clicking the mask or the Close button fades it out again. This demonstrates the declarative state-driven plus CSS transition approach that real Framer Motion implements with motion.div and AnimatePresence.

💡 Key Points

💡 Tip The exit prop plus AnimatePresence is the standard combination for modal and list-item exits; plain CSS cannot animate an element that is being unmounted.
ℹ️ Info Since v11 the official package is motion with an almost identical API and the import path motion/react; the old framer-motion package keeps working.
⚠️ Warning With several hundred animated elements on screen, watch the performance: prefer transform and opacity, or limit the scope of CSS transitions and layout animations.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q How do I choose between Framer Motion and CSS animation?
A Plain CSS is enough for simple hover and fade-in effects; use Framer Motion when you need state-driven choreography, exit animations, gesture interaction, spring physics or layout animations — it reads React state directly.
Q What does AnimatePresence do?
A When React unmounts an element it removes the DOM node immediately, so CSS never gets the chance to play an exit animation. AnimatePresence delays the unmount so the exit animation finishes before the node is really removed.
Q What is the relation between the new motion package and framer-motion?
A After Framer Motion v11 the team ships a standalone motion package with a compatible API: the import becomes motion/react and it also works with plain JavaScript. The old package is still maintained, and new projects should start with motion.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏