Skip to main content
Albero Academy

Transitions & Animations

Bring interfaces to life — smooth transitions on state change, keyframe animations, timing functions, and honouring reduced motion.

Chapter 14CSS15 min readBeginner friendly
  • #CSS
  • #Animation
  • #Transitions

Motion, used sparingly, makes an interface feel responsive and polished. CSS handles it without JavaScript: transitions animate a change from one state to another, and animations run multi-step sequences. The art is restraint — subtle beats flashy.

Transitions

A transition smoothly animates a property when its value changes (on hover, focus, or a class toggle). Declare what to animate and how long:

smooth state changes
.button {
background: #2563eb;
transition: background 0.2s ease, transform 0.2s ease;
}
.button:hover {
background: #1e3a8a;
transform: translateY(-2px);
}
/* transition: property duration timing-function delay; */

Timing functions

FunctionFeel
easeDefault — gentle start and end
linearConstant speed (good for spinners)
ease-outFast then slow (great for entrances)
cubic-bezier(…)Custom curves — even overshoot

Keyframe animations

For multi-step or looping motion, define @keyframes and apply it with animation:

@keyframes
@keyframes fade-in-up {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: translateY(0); }
}
.card { animation: fade-in-up 0.5s ease-out both; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 1s linear infinite; }

Performance & reduced motion

  • Animate transform and opacity — the GPU handles them smoothly. Animating width, top or margin forces layout recalculation and stutters.
  • Respect users who prefer less motion — a genuine accessibility need:
honour prefers-reduced-motion
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}

Practice

Add a hover transition to a button (background + a translateY lift). Write a fade-in-up @keyframes and apply it to cards, and a spinning loader with animation … infinite. Then add a prefers-reduced-motion block that disables it all.

Key takeaways

  1. 01transition animates a property when its value changes; syntax: property duration timing delay.
  2. 02Never transition: all — list specific properties; prefer transform/opacity.
  3. 03Timing functions (ease, linear, ease-out, cubic-bezier) set the motion feel.
  4. 04@keyframes + animation run multi-step or looping sequences (infinite, both).
  5. 05Animate transform/opacity for smoothness, and honour prefers-reduced-motion.