/

HTML / CSS / JavaScript Tutorial

CSS Property: animation-play-state

[this page | pdf | back links]

The CSS (CSS3) animation-play-state property specifies whether the animation is paused or not. One of its uses is to pause an animation in the middle of a cycle using JavaScript.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

paused

Specifies animation is paused

running

(default value). Specifies animation is running

 

Default Value:

running

JavaScript syntax:

e.g. object.style.animationPlayState = "paused";

Inherited:

No

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {width: 100px; height: 40px; position: relative; 
  background: yellow; animation: anim 2s infinite;}
div.x1 {animation-play-state: running;}
@keyframes anim {from {left: 0px} to {left: 50px;} } 
</style>
</head>
<body>
1. Element set using in-file HTML style<br>
<div class="x1">&nbsp;</div><br><br>
2. Element set using JavaScript<br>
<div id="x2">&nbsp;</div>

<script>
document.getElementById("x2").style.animationPlayState = "paused";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyAnimationPlayState() {
  var x = document.createElement("DIV"); x.style.animationPlayState = "paused"; return (window.getComputedStyle(x, null).animationPlayState == "paused");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile