Web Analytics

CSS Animations

Intermediate ~10 min read

What are Animations?

CSS animations let you create complex, multi-step animations using @keyframes. Unlike transitions, animations can run automatically and loop!

Basic Keyframes

Define animation steps with @keyframes, then apply with animation-name and animation-duration.

HTML
CSS
JS

Percentage Keyframes

Use percentages for multi-step animations. 0% = start, 100% = end.

HTML
CSS
JS

Animation Iteration

animation-iteration-count controls how many times the animation runs. Use infinite for endless loops.

HTML
CSS
JS

Animation Direction

animation-direction controls playback: normal, reverse, alternate, alternate-reverse.

HTML
CSS
JS

Animation Fill Mode

animation-fill-mode controls styles before/after animation: none, forwards, backwards, both.

HTML
CSS
JS

Animation Shorthand

Combine all properties: animation: name duration timing-function delay iteration-count direction fill-mode.

HTML
CSS
JS
Pro Tip: Use animation-play-state: paused on hover to pause animations for better UX. Great for loading spinners!

Summary

  • @keyframes - Define animation steps
  • animation-name - Which keyframe to use
  • animation-duration - How long
  • animation-iteration-count - How many times
  • animation-direction - Playback direction
  • animation-fill-mode - Before/after styles
  • Use infinite for endless loops

Quick Quiz

Which value makes an animation loop forever?

A
loop
B
infinite
C
repeat
D
forever