CSS Transitions & Timing Functions
Eliminate jarring, abrupt visual snaps. Learn how the browser calculates intermediate animation frames, master the sacred 60fps GPU rule (transform & opacity only!), and build snappy bouncy interfaces with custom cubic-bezier() curves.
1. Mental Model: Elevator Doors vs. Sci-Fi Teleportation
When a CSS pseudo-state (like :hover or :active) matches, the browser instantly changes properties in a single frame (0ms). To the human eye, this feels unnatural, robotic, and abrasive.
A transition tells the browser: "Don't teleport immediately. Interpolate smoothly from State A to State B over 300 milliseconds using physics curves!"
2. The Sacred 60fps Rule: What Properties Can You Safely Animate?
| Category | CSS Properties | Browser Pipeline Cost | Frame Rate Performance |
|---|---|---|---|
| GPU Composited (Gold Standard) | transform, opacity | Compositing ONLY (Zero layout, zero repaint!) | Silky Smooth 60fps / 120fps ProMotion |
| Paint Triggering | color, background-color, box-shadow | Triggers Paint + Composite | Fine for small buttons; lags full-screen elements |
| Layout Thrashing (The CPU Killer) | width, height, top, left, margin, padding | Triggers Layout + Paint + Composite! | Horrible stuttering and battery drain |
3. Interactive Studio: Live Timing Function Race Track
Notice how the elastic bounce timing function overshoots its target and settles back into place naturally!
First-Year Student Traps: Transitions
- 1.Never write
transition: all 0.3s;! Transitioning "all" forces the browser to watch and recalculate all 300+ CSS properties on every frame. If an ancestor element changes font or color, the entire DOM tree stutters. Always specify exact properties:transition: transform 0.2s ease, opacity 0.2s ease;. - 2.Putting transition inside :hover instead of the base class: If you write
.btn:hover { transition: transform 0.3s; }, the button will animate smoothly when mouse enters, but snap abruptly back when the mouse leaves! Placetransitionon the base.btnselector so it animates smoothly both ways.
Keyframe Animations & animation-fill-mode
Create autonomous loops, multi-step choreographies with @keyframes, and embedded Animation Studio.