Motion (Framer Motion) — Modern Animation Library for React & JS
Motion (formerly Framer Motion) is a modern animation library for React and JavaScript with a simple declarative API. Hardware-accelerated transforms, gestures, layout animations, and SVG morphing — all in a tiny package.
What it is
Motion (formerly Framer Motion) is a modern animation library for React and vanilla JavaScript. It provides a simple declarative API for hardware-accelerated transforms, gesture recognition, layout animations, scroll-triggered animations, and SVG path morphing. The library handles the complexity of performant animations while keeping the developer API minimal.
This tool is for frontend developers who need smooth, production-quality animations without writing raw CSS keyframes or JavaScript requestAnimationFrame loops.
How it saves time or tokens
Motion abstracts animation complexity into a few props. What would require dozens of lines of CSS and JavaScript becomes a single <motion.div> component with animate, whileHover, and layout props. Gesture detection, spring physics, and layout change animations work out of the box. For AI-assisted frontend development, generating Motion animations requires minimal code.
How to use
- Install Motion via npm.
- Import the
motioncomponent. - Add animation props to your JSX elements.
- Motion handles the rest: physics, performance, and cleanup.
# Install Motion
npm install motion
# For React
npm install framer-motion
Example
import { motion } from 'framer-motion'
function AnimatedCard() {
return (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
transition={{ type: 'spring', stiffness: 300 }}
className='card'
>
<h2>Animated Card</h2>
<p>This card animates in, responds to hover and tap.</p>
</motion.div>
)
}
// Layout animation: smooth transitions when list items reorder
function AnimatedList({ items }) {
return (
<ul>
{items.map(item => (
<motion.li
key={item.id}
layout
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
{item.name}
</motion.li>
))}
</ul>
)
}
Related on TokRepo
- AI coding tools — Frontend development tools
- Design tools — UI and animation design
Common pitfalls
- Animating layout properties (width, height) can cause layout thrashing. Use
transformproperties (x, y, scale, rotate) whenever possible for GPU-accelerated performance. - The
layoutprop triggers re-renders. In lists with many items, this can cause performance issues. UselayoutIdselectively. - Motion adds bundle size. If you only need simple CSS transitions, consider native CSS instead of importing the full library.
- Exit animations require
AnimatePresencewrapper. Forgetting it means components disappear without animation. - Spring animations look natural but can overshoot. Tune
stiffnessanddampingvalues for your use case. - Review the official documentation before deploying to production to ensure compatibility with your specific environment and requirements.
Frequently Asked Questions
Yes. The library was renamed from Framer Motion to Motion. The React package is still framer-motion on npm. The standalone JavaScript version is available as the motion package.
Yes. Motion works with Next.js including App Router and Server Components. The motion components are client components, so use the 'use client' directive in files that use animations.
Motion uses hardware-accelerated CSS transforms by default, runs animations on the compositor thread when possible, and batches DOM reads and writes. It avoids layout thrashing by preferring transform properties.
Yes. Use AnimatePresence with your router to animate page transitions. Motion supports exit animations that play before the component unmounts, enabling smooth route transitions.
Yes. Motion provides useScroll, useMotionValueEvent, and whileInView for scroll-driven animations. Elements can animate as they enter or exit the viewport.
Citations (3)
- Motion GitHub— Motion is a modern animation library for React
- Motion Documentation— Framer Motion API reference and examples
- MDN Web Docs - CSS Animations— Hardware-accelerated CSS animations
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.