Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

CSS
CSS
0/10 completed
Beginner
Selectors and propertiesColors and fontsThe box modelDisplay and positioning
Intermediate
FlexboxCSS GridResponsive design
Advanced
Transitions and animationsCSS variables and architecture
Pro
Modern CSS: :has(), container queries and layers
Tracks / CSS / Advanced

Transitions and animations

Motion makes interfaces feel alive and helps users understand changes: a button responding to a click, a menu sliding open, a loading spinner. CSS can do all of this without JavaScript.

Transitions: smooth changes between states

A transition animates a property when it changes, for example on :hover or when a class is added.

HTML · CSS · live preview
Preview
css
transition: <property> <duration> <timing-function> <delay>;

Timing functions

HTML · CSS · live preview
Preview

UI motion guideline: keep it short (150–300ms). Use ease-out for things entering and ease-in for things leaving.

Transforms

transform moves, rotates, scales and skews elements without affecting the layout, so neighbouring elements don't move.

HTML · CSS · live preview
Preview

Keyframe animations

@keyframes defines a multi-step animation that can loop, run on page load, or play many times.

HTML · CSS · live preview
Preview
Property Example
animation-name pulse
animation-duration 1.2s
animation-timing-function ease-in-out
animation-delay 300ms
animation-iteration-count 3, infinite
animation-direction alternate (play forwards, then backwards)
animation-fill-mode both (keep the first/last frame styles)

Performance: animate only transform and opacity

Browsers can animate transform and opacity on the GPU, smoothly, at 60fps. Animating width, height, top, left or margin forces the browser to recalculate the layout on every frame, which causes jank.

css
/* ✗ Janky */
.panel { transition: left 300ms; }
/* ✓ Smooth */
.panel { transition: transform 300ms; }

Respect reduced motion

Some users get dizzy or nauseous from motion and turn on "reduce motion" in their OS. Honour it:

css
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

Practice

Create:

  1. A card that lifts and grows its shadow on hover (a transition).
  2. A three-dot "typing…" loading indicator where each dot bounces with a staggered animation-delay (keyframes).
  3. Make sure both respect prefers-reduced-motion.
HTML · CSS · live preview
Preview
✎ Check your understanding

1.Which properties are cheapest to animate?

2.What's the difference between a transition and a keyframe animation?

← Responsive design