# UI Animation with Motion Libraries

> Add purposeful motion with Motion (Framer Motion), the View Transitions API and, when needed, GSAP, while respecting reduced motion. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/frontend/motion
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/frontend/css-motion), [Rendering, Reconciliation and Memoisation](https://www.internhack.in/roadmaps/tracks/frontend/react-rendering)

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.
- `AnimatePresence` animates components as they **unmount**, which CSS alone cannot do.
- **Layout animations** (`layout` prop, `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 `transform` and `opacity` for smoothness.
- Always honour `prefers-reduced-motion` (Motion's `useReducedMotion`), 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](https://motion.dev/docs/react) (Motion)
- [View Transition API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) (MDN)
- [GSAP documentation](https://gsap.com/docs/v3/) (GSAP)

Previous: [Storybook and Component Documentation](https://www.internhack.in/roadmaps/tracks/frontend/storybook) · Next: [Internationalisation and Localisation](https://www.internhack.in/roadmaps/tracks/frontend/i18n)

## More in Design Systems, Motion and Internationalisation

- [Design Tokens and Theming](https://www.internhack.in/roadmaps/tracks/frontend/design-tokens)
- [Component Libraries: shadcn/ui and Radix](https://www.internhack.in/roadmaps/tracks/frontend/component-libraries)
- [Storybook and Component Documentation](https://www.internhack.in/roadmaps/tracks/frontend/storybook)
- [UI Animation with Motion Libraries](https://www.internhack.in/roadmaps/tracks/frontend/motion)
- [Internationalisation and Localisation](https://www.internhack.in/roadmaps/tracks/frontend/i18n)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Frontend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/frontend)
