CSS propertyAnimations
animation-play-state
Pauses or resumes an animation.
- Initial value
running- Inherited
- No
- Animatable
- no
- Applies to
- all elements and the ::before and ::after pseudo-elements
- JavaScript
element.style.animationPlayState = "paused"
Example
#CSS
.marquee {
animation: scroll 12s linear infinite;
}
.marquee:hover {
animation-play-state: paused;
}Example HTML
<style>
@keyframes scroll-x { to { transform: translateX(-50%); } }
.mq { display: flex; gap: 24px; width: max-content; animation: scroll-x 12s linear infinite; }
.mq:hover { animation-play-state: paused; }
</style>
<div style="overflow: hidden;"><div class="mq"><span>HTML</span><span>CSS</span><span>JavaScript</span><span>TypeScript</span><span>Python</span><span>HTML</span><span>CSS</span><span>JavaScript</span><span>TypeScript</span><span>Python</span></div></div>Preview
Definition and usage
#The animation-play-state property takes two values: running (the animation plays) and paused (the animation stands still). After resuming, the animation continues from the point where it was stopped, not from the beginning.
A popular pattern is pausing the animation on hover, for example a scrolling strip of logos, so the content can be read.
You can also toggle the state in JavaScript, for example by pausing animations when the element is not visible on screen.
Syntax
#Syntax
animation-play-state: running | paused [, β¦]*;Values
#Values in practice
#running
The gear rotates.
.demo { animation-play-state: running; }paused
The gear stands still where it stopped.
.demo { animation-play-state: paused; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Pause a strip of scrolling items on hover and on keyboard focus.
- Pausing animations that are off screen saves battery on phones.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.