When CSS Transitions Are Enough
What you'll learn: How to recognize when native CSS transitions can handle your animation needs without reaching for JavaScript libraries.
The Core Idea
Before pulling in heavy animation libraries like Framer Motion or React Spring, pause and ask: "Does this actually need JavaScript?" Many common UI animations—hover effects, fades, slides, scale transforms—work perfectly with plain CSS transition properties. Since you're already using CSS (whether via modules, Tailwind, styled-components, or vanilla-extract), leveraging transitions means zero additional bundle size and often better performance.
When CSS Transitions Shine
CSS transitions excel at state-based animations where you're toggling between two defined states:
- Hover and focus effects (button grows slightly, background changes)
- Show/hide patterns with opacity and transform
- Theme transitions (background color shifts when switching light/dark mode)
- Simple loading indicators (pulsing dots, rotating spinners)
The pattern is simple: you change a class name or CSS variable from React, and CSS handles the animation automatically. Since React already re-renders when state changes, adding a class like isOpen or isActive triggers the transition without any animation-specific JavaScript.
The Performance Win
CSS transitions run on the browser's compositor thread when animating transform and opacity properties. This means smoother 60fps animations without blocking JavaScript execution. No library overhead, no React re-renders during animation, no bundle cost.
When You Need More
CSS transitions fall short when you need: complex orchestration (stagger effects), physics-based motion, interruption handling, or animating to unknown values. That's when libraries become worth their weight.
Key Takeaway: Start with CSS transitions for simple state changes—they're performant, have zero bundle cost, and work seamlessly with any styling solution. Only reach for JavaScript animation libraries when you need features CSS can't provide.