# Transitions and CSS Animations

> Add motion that communicates state changes using transitions, keyframes and transforms, while staying fast and respectful of user preferences. Free notes, key...

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

Add motion that communicates state changes using transitions, keyframes and transforms, while staying fast and respectful of user preferences.

Intermediate · about 3 hours · difficulty 2/5

Learn first: [Custom Properties and Modern CSS Features](https://www.internhack.in/roadmaps/tracks/frontend/modern-css)

Motion helps users understand what changed: a menu slides from the button that opened it, a toast fades in, a loading state pulses. Bad motion is slow, janky or nauseating.

### Transitions

`transition: transform 200ms ease-out, opacity 200ms;` animates between two states when a property changes (on hover, focus or a class toggle). Keep UI transitions short: roughly 150 to 300ms.

### Keyframe animations

`@keyframes` define multi-step sequences, applied with `animation: spin 1s linear infinite`. Use them for loaders, attention cues and entrance effects. `animation-fill-mode` controls what happens before and after.

### Transforms and performance

`transform` (translate, scale, rotate) and `opacity` can be animated on the compositor without layout or paint, so they stay smooth at 60fps. Animating `width`, `height`, `top` or `box-shadow` triggers layout or paint on every frame. `will-change` is a hint for the browser; use it sparingly.

### Easing and accessibility

- `ease-out` feels responsive for things entering; `ease-in` suits exits. `cubic-bezier()` and the newer `linear()` allow custom curves.
- Wrap non-essential motion in `@media (prefers-reduced-motion: no-preference)` or reduce it under `reduce`.
- Never convey information only through animation.

Move on when you can build an animated disclosure, a skeleton loader and a hover effect that all run smoothly in the Performance panel and switch off under reduced motion.

## Key concepts

- **transition property**
- **@keyframes and animation**
- **transform functions**
- **Compositor-friendly properties**: transform and opacity
- **Easing functions**
- **prefers-reduced-motion**
- **will-change**

## Mini project

Create a notification toast system in plain HTML/CSS/JS: toasts slide in, stack, auto-dismiss with a progress bar, and use a simple fade under reduced motion.

## Check yourself

Why does animating height often stutter while animating transform: scaleY does not?

## Free resources

- [Learn CSS: Animations](https://web.dev/learn/css/animations) (web.dev)
- [Using CSS animations](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) (MDN)

Previous: [Custom Properties and Modern CSS Features](https://www.internhack.in/roadmaps/tracks/frontend/modern-css) · Next: [JavaScript Syntax and Fundamentals](https://www.internhack.in/roadmaps/tracks/frontend/js-fundamentals)

## More in Responsive and Modern CSS

- [Responsive Design](https://www.internhack.in/roadmaps/tracks/frontend/responsive-design)
- [Custom Properties and Modern CSS Features](https://www.internhack.in/roadmaps/tracks/frontend/modern-css)
- [Transitions and CSS Animations](https://www.internhack.in/roadmaps/tracks/frontend/css-motion)

## Related

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