UI Animation with Motion Libraries
Add purposeful motion with Motion (Framer Motion), the View Transitions API and, when needed, GSAP, while respecting reduced motion.
Intermediate · about 4 hours · difficulty 3/5
Learn first: Transitions and CSS Animations, Rendering, Reconciliation and Memoisation
Good motion explains what changed: a panel slides from the button that opened it, a list item fades out when deleted, a page transition shows where you came from. Bad motion is slow, distracting or nauseating. Master CSS transitions first; reach for libraries when you need orchestration, gestures or layout animation.
Motion (formerly Framer Motion)
The most popular React animation library:
<motion.div animate={{ opacity: 1, y: 0 }} initial={{ opacity: 0, y: 8 }} />declarative animations.AnimatePresenceanimates components as they unmount, which CSS alone cannot do.- Layout animations (
layoutprop,layoutId) smoothly animate size and position changes, including shared element transitions. - Gestures (hover, tap, drag), variants for orchestrating children, and spring physics for natural feel.
View Transitions API
A browser API that animates between two DOM states or pages: document.startViewTransition(() => updateDom()), styled with CSS pseudo-elements. Cross-document view transitions work for multi-page sites too. Frameworks increasingly integrate it.
GSAP (optional)
A powerful timeline-based animation library for complex, choreographed sequences, scroll-driven storytelling (ScrollTrigger) and SVG animation. Common on marketing and award-style sites. CSS scroll-driven animations now cover some of these cases natively.
Principles
- Keep UI transitions short (roughly 150 to 300 ms) with easing that decelerates.
- Animate
transformandopacityfor smoothness. - Always honour
prefers-reduced-motion(Motion'suseReducedMotion), replacing movement with fades or nothing. - Motion should never block the user from acting.
Good enough to move on
You can animate a list with enter and exit transitions, a shared-element card-to-detail transition and a reduced-motion alternative for each.
Key concepts
- Purposeful motion principles
- Motion (Framer Motion) basics
- AnimatePresence exit animations
- Layout and shared element animations
- View Transitions API
- GSAP and ScrollTrigger
- Reduced motion support
Mini project
Build a photo gallery where thumbnails expand into a detail view with a shared-element transition, deleted photos animate out with AnimatePresence, and everything degrades to simple fades under prefers-reduced-motion.
Check yourself
Why can CSS transitions alone not animate a component that React removes from the DOM, and how does AnimatePresence solve it?
Free resources
- Motion for React (Motion)
- View Transition API (MDN)
- GSAP documentation (GSAP)