Course contentsShow
← Web Development
Lesson 524 of 2,9829. CSS Transitions and AnimationsFree lesson

The animation-play-state Property

Pause and resume running animations dynamically using play state control.

The animation-play-state Property

What you'll learn: How to pause and resume CSS animations on demand, giving you real-time control over animation playback.


Understanding Animation Playback Control

Think of animation-play-state like the pause button on a video player. Once an animation starts running, you can freeze it mid-motion and later resume exactly where it left off. This property accepts two values:

  • running — The animation plays normally (this is the default)
  • paused — The animation stops in place but remembers its current position

Basic Syntax

.element {
  animation-name: slide;
  animation-duration: 3s;
  animation-play-state: running; /* default */
}

.element:hover {
  animation-play-state: paused;
}

In this example, the animation runs normally until you hover over the element—then it freezes. Move your cursor away, and it continues from where it stopped.

Common Use Cases

The most practical pattern is pausing animations when users interact with animated elements:

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.loading-spinner {
  animation-name: spin;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-play-state: running;
}

.loading-spinner.paused {
  animation-play-state: paused;
}

You can toggle the .paused class with JavaScript to control when the spinner stops and starts, which is especially useful for accessibility (letting users pause distracting motion) or performance optimization (pausing off-screen animations).

Why This Matters

Unlike stopping an animation entirely, paused preserves the animation's current frame. When you switch back to running, the animation picks up seamlessly—no jarring reset to the beginning.

Key Takeaway: Use animation-play-state to pause and resume animations dynamically, with paused freezing the animation in place and running continuing playback from the current position.