Skip to main content
Frontend Engineering

Framer Motion Animation & Gestures

Production

Declarative React animations, AnimatePresence transitions, exit animations, hover/tap gestures, and layout morphing.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Framer Motion Animation & Gestures Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (16 Total Commands).

16+ Verified Recipes
Fade & Slide Ininitial, animate, transition
<motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.4, ease: "easeOut" }} > {content} </motion.div>

Smooth entrance animation triggering when element mounts into DOM.

Exit Animations<AnimatePresence>, exit
<AnimatePresence mode="wait"> {isVisible && ( <motion.div key="modal" initial={{ scale: 0.9, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.9, opacity: 0 }} /> )} </AnimatePresence>

Animate elements smoothly as they are removed from React component tree.

Hover & Tap GestureswhileHover, whileTap
<motion.button whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }} transition={{ type: "spring", stiffness: 400, damping: 17 }} > Click Me </motion.button>

Interactive micro-animations for buttons and interactive cards.

Layout Morphinglayout, layoutId
<motion.div layout layoutId="active-indicator" className="underline" />

Automatically animate layout changes and smoothly morph between DOM positions.

Imperative AnimationuseAnimation
const controls = useAnimation(); useEffect(() => { controls.start({ opacity: 1, y: 0 }); }, []);

Programmatically trigger animation sequences from lifecycle events using animation controls.

Scroll Progress TrackinguseScroll
const { scrollYProgress } = useScroll(); <motion.div style={{ scaleX: scrollYProgress }} className='progress-bar' />

Bind CSS transform properties directly to viewport or container scroll progress.

Motion Value MappinguseMotionValue, useTransform
const x = useMotionValue(0); const opacity = useTransform(x, [-100, 0, 100], [0, 1, 0]);

Declaratively map motion coordinates to visual attributes without triggering component re-renders.

Interactive Draggingdrag, dragConstraints
<motion.div drag='x' dragConstraints={{ left: -100, right: 100 }} dragElastic={0.2}>

Enable physics-based drag gestures constrained by boundaries and elastic damping.

In-View AnimationsuseInView
const ref = useRef(null); const inView = useInView(ref, { once: true }); <motion.div ref={ref} animate={inView ? 'visible' : 'hidden'} variants={variants}>

Trigger entrance animations automatically once element intersects the browser viewport.

Staggered ChildrenstaggerChildren
const variants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.1 } } };

Coordinate child element animations with sequential delay intervals.

Lazy Motion BundlesLazyMotion, domAnimation
<LazyMotion features={domAnimation}> <m.div animate={{ opacity: 1 }} /> </LazyMotion>

Trim 15KB from JavaScript bundle by loading only DOM animation features asynchronously.

Gesture Micro-InteractionswhileHover, whileTap
<motion.button whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }}>

Provide tactile micro-interaction scaling feedback on pointer hover and tap events.

Realistic Springstype: 'spring'
transition={{ type: 'spring', stiffness: 300, damping: 20 }}

Configure natural physics spring simulation with stiffness, damping, and mass parameters.

FLIP Layout Animationslayout
<motion.ul layout> {items.map(i => <motion.li layout key={i.id}>{i.name}</motion.li>)} </motion.ul>

Smoothly animate element repositioning when lists are filtered, sorted, or mutated.

Exit State DetectionuseIsPresent
const isPresent = useIsPresent();

Detect whether component is actively mounted or currently executing an exit animation.

Dynamic Height Accordionsheight: 'auto'
<motion.div initial={false} animate={{ height: isOpen ? 'auto' : 0 }} className='overflow-hidden'>

Animate smooth accordion transitions between collapsed zero-height and dynamic auto height.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Framer Motion Animation & Gestures: Command Groups & Quick Index

16 indexed entries across 16 sections
Fade & Slide In1 items
Exit Animations1 items
Hover & Tap Gestures1 items
Layout Morphing1 items
Imperative Animation1 items
Scroll Progress Tracking1 items
Motion Value Mapping1 items
Interactive Dragging1 items
In-View Animations1 items
Staggered Children1 items
Lazy Motion Bundles1 items
Gesture Micro-Interactions1 items
Realistic Springs1 items
FLIP Layout Animations1 items
Exit State Detection1 items
Dynamic Height Accordions1 items

Highlighted Flags & Syntax Examples in Framer Motion Animation & Gestures

<motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.4, ease: "easeOut" }} > {content} </motion.div>

Smooth entrance animation triggering when element mounts into DOM.

Flags: initial, animate, transition
<AnimatePresence mode="wait"> {isVisible && ( <motion.div key="modal" initial={{ scale: 0.9, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.9, opacity: 0 }} /> )} </AnimatePresence>

Animate elements smoothly as they are removed from React component tree.

Flags: <AnimatePresence>, exit
<motion.button whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }} transition={{ type: "spring", stiffness: 400, damping: 17 }} > Click Me </motion.button>

Interactive micro-animations for buttons and interactive cards.

Flags: whileHover, whileTap
<motion.div layout layoutId="active-indicator" className="underline" />

Automatically animate layout changes and smoothly morph between DOM positions.

Flags: layout, layoutId

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Framer Motion Animation & Gestures.

Why is layoutId useful in Framer Motion tab navigation?

When elements in different parts of the component tree share the same layoutId, Framer Motion automatically creates a seamless cross-fade and geometric morph between them when one unmounts and the other mounts.

What is the difference between spring and tween transitions?

A tween transition runs for a fixed duration using mathematical easing curves (linear, easeOut). A spring transition simulates physical mass, stiffness, and damping, providing dynamic, organic-feeling motion.

How does FLIP (First, Last, Invert, Play) animation work in Framer Motion's layout prop?

When state changes, Framer Motion measures the element's initial position (First) and new position (Last). It then applies a CSS transform inverting the change so the element appears at its original spot (Invert), and removes the transform to animate smoothly to the new position (Play). This allows performant 60fps layout animations using GPU-accelerated transforms rather than expensive layout reflows.

Why should you use LazyMotion and domAnimation instead of standard motion components?

Standard 'motion' components import all Framer Motion features (gestures, drag, SVG paths, layout animations) into the main bundle (~34KB gzipped). Wrapping your tree in '<LazyMotion features={domAnimation}>' and using '<m.div>' loads only the basic animation features (~17KB gzipped), deferring heavy features until requested.

What is the difference between useMotionValue and standard React useState for animations?

React useState triggers a full component re-render on every state change, which degrades frame rates during rapid 60fps animations like drags or scroll tracking. 'useMotionValue' stores state outside of React's render loop and mutates DOM styles directly without re-rendering the component.

How does AnimatePresence handle exit animations when components are unmounted?

'AnimatePresence' intercepts React's unmount lifecycle. When a child component is removed from the React tree, AnimatePresence defers actual DOM deletion until the child's 'exit' animation completes, enabling smooth exit transitions before clean unmounting.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets