1. Why Do We Need Transitions and Animations?
Motion in web design is not mere decoration; it is communication and visual feedback. A button that lifts on hover signals clickability; a modal that fades in directs user focus; a spinner reassures the user that an API call is processing.
2. The Core Mental Model: Transitions vs Animations
CSS Transitions
Smooth change from State A to State B triggered by a user interaction (:hover, :focus, class change). Two endpoints only.
Keyframe Animations
Autonomous multi-step sequence (0% ➔ 50% ➔ 100%) that runs automatically, loops infinitely, and requires no user interaction trigger.
3. CSS Transitions Deep Dive
transition-property: transform, opacity, background-color;
transition-duration: 0.3s;
transition-timing-function: ease-in-out;
transition-delay: 0.05s;
/* The Standard Shorthand: property duration timing delay */
transition: transform 0.3s ease 0s, background-color 0.2s ease;
4. Creating Your First Interactive Transition
background: #ec4899;
transform: translateY(0) scale(1);
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-glow:hover {
transform: translateY(-3px) scale(1.05);
box-shadow: 0 8px 24px rgba(236, 72, 153, 0.5);
}
5. CSS Transform Mechanics (GPU Accelerated)
translate(x, y)
Moves element across X and Y axes without affecting document flow.
scale(val)
Resizes element up or down (e.g. scale(1.1) is 10% larger).
rotate(deg)
Rotates element clockwise (e.g. rotate(45deg), rotate(360deg)).
skew(deg)
Distorts element along horizontal and vertical angles.
6. Timing Functions & Easing Curves
| Timing Function | Acceleration Curve | Best Used For |
|---|---|---|
ease (Default) | Starts fast, slows down at the end | General UI state changes and button hovers |
linear | Constant speed from start to finish | Continuous spinning loaders and progress bars |
ease-in | Starts slowly, accelerates at the end | Exit animations (items dropping off screen) |
ease-out | Starts quickly, decelerates gently | Entrance animations (modals popping onto screen) |
ease-in-out | Slow start, fast middle, slow end | Smooth looping pulse and floating cards |
7. CSS Keyframe Animations Architecture
.pulse-element {
animation: pulse 1.5s ease-in-out 0s infinite alternate forwards;
}
8. Creating Keyframe Timelines: 0% ➔ 50% ➔ 100%
0% {
transform: translateY(0);
opacity: 1;
}
50% {
transform: translateY(-16px);
opacity: 0.8;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
9. 5 Production Motion Patterns
1. Fade & Slide In
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
2. Infinite Spinner
to { transform: rotate(360deg); }
}
animation: spin 1s infinite linear;
3. Pulse Glow
0%, 100% { transform: scale(1); }
50% { transform: scale(1.08); }
}
10. When to Use Transitions vs Keyframe Animations
- Use Transitions when: Responding to direct user intent (button hovers, accordion expanding, dark-mode color shifts, active tab switches).
- Use Keyframe Animations when: Creating continuous ambient effects (loaders, pulsing badges, page entrance stagger sequences, complex multi-step timelines).
11. 60 FPS Performance: Compositor vs Layout vs Paint
The browser rendering pipeline has 3 stages: Layout (Reflow) ➔ Paint ➔ Composite.
| Pipeline Stage | Triggering CSS Properties | Performance Impact |
|---|---|---|
| Layout (Reflow) | width, height, top, left, margin, padding | 🔴 Terrible. Recalculates page geometry for every frame (causes stutter/jank). |
| Paint | background-color, box-shadow, border-color | 🟡 Moderate. Repaints pixel bitmap colors. |
| Composite (GPU) | transform, opacity | 🟢 60 FPS Silky Smooth. Executed directly on the GPU compositor thread! |
12. Web Accessibility & prefers-reduced-motion
Millions of users suffer from vestibular disorders where aggressive screen motion induces vertigo, nausea, and motion sickness. Always respect their system preferences:
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
13. Common Animation Mistakes
- Animating
toporleft: Always replace withtransform: translate(x, y)to avoid dropping frames. - Over-animating everything: If every card, paragraph, and button spins and bounces, it overwhelms the user and ruins perceived speed.
- Overly long durations: UI micro-interactions should last between 150ms and 300ms. Durations > 500ms make the site feel sluggish.
14. Practical Animated Toast Notification
position: fixed;
bottom: 24px;
right: 24px;
background: #110e1c;
border: 1px solid #ec4899;
border-radius: 12px;
animation: toastSlideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes toastSlideIn {
from { transform: translateY(100px) scale(0.9); opacity: 0; }
to { transform: translateY(0) scale(1); opacity: 1; }
}
15. Motion Best Practices Checklist
- Stick to
transformandopacityfor 60fps animations. - Keep hover micro-interactions snappy (150ms–250ms).
- Include
@media (prefers-reduced-motion: reduce)in your CSS reset.