- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS animation-play-state Control Animation Playback
Control whether animations are running or paused.
Available options include 'running' and 'paused'.
CSS animation-play-state
Property
The animation-play-state
property in CSS allows you to control whether an animation is running or paused. This is useful for creating interactive elements that respond to user actions, such as hovering over an element or clicking a button.
Description
The animation-play-state
property in CSS is used to specify whether an animation is currently running or paused. This property can be applied to single or multiple animations, allowing you to control each animation’s playback state individually.
Syntax
Here’s how to use the animation-play-state
property in your CSS code:
running
: The animation is currently playing.paused
: The animation is currently paused.inherit
,initial
,revert
,revert-layer
, andunset
are global values that control inheritance and reset behaviors.
Values
The animation-play-state
property accepts the following values:
running
: The animation is currently playing.paused
: The animation is currently paused.inherit
: Inherits the playback state from the parent element.initial
: Sets the playback state to its default value (running
).revert
: Reverts the playback state to the value specified by the user agent or user stylesheet.revert-layer
: Reverts the playback state considering the cascade layer.unset
: Resets the playback state to its natural value.
Formal Definition
Here’s the formal definition of the animation-play-state
property:
Initial value | running |
---|---|
Applies to | All elements, ::before and ::after pseudo-elements |
Inherited | No |
Computed value | As specified |
Animation type | Not animatable |
The property syntax is:
Examples
Pausing and Running an Animation on Hover
In this example, we create an animation that is paused initially and starts running when the user hovers over the element.
HTML
CSS
Result
Hover over the rectangle to play the animation.
Running Animation Continuously
In this example, we create a running animation that moves a green square across the screen continuously from left to right.
HTML
Output
The green square will continuously move from left to right across the screen.
Paused Animation
In this example, we create a paused animation that halts the movement of a green square across the screen.
HTML
Output
The green square will remain stationary, demonstrating a paused animation.
Supported Browsers
The animation-play-state
property works in many modern browsers:
- Google Chrome: Since version 5.0.
- Microsoft Edge: Since version 12.
- Mozilla Firefox: Since version 4.0.
- Safari: Since version 5.0.
- Opera: Since version 11.1.
FAQs
What is the animation-play-state
property in CSS?
The animation-play-state
property controls whether an animation is running or paused. It helps you pause and resume animations.
Does animation-play-state
affect animations on page load?
If you set animation-play-state: paused
, the animation won’t start when the page loads. It stays paused until set to running
.
What is the default value of animation-play-state
?
The default value is running
, so the animation starts immediately.
Does animation-play-state
affect completed animations?
No, once an animation is complete, setting animation-play-state: running
won’t restart it. You need to re-trigger the animation.
Can I control the animation-play-state
with JavaScript?
Yes, you can use JavaScript to control the animation state dynamically.
Browser Compatibility
The animation-play-state
property is widely supported:
- Google Chrome: Since version 5.0.
- Microsoft Edge: Since version 12.
- Mozilla Firefox: Since version 4.0.
- Safari: Since version 5.0.
- Opera: Since version 11.1.
See Also
For more details, check out:
- Using CSS animations
- JavaScript
AnimationEvent
API - Other related animation properties:
animation
,animation-composition
,animation-delay
,animation-direction
,animation-duration
,animation-fill-mode
,animation-iteration-count
,animation-name
,animation-timeline
,animation-timing-function
Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.