/

HTML / CSS / JavaScript Tutorial

CSS Property: animation-duration

[this page | pdf | back links]

The CSS (CSS3) animation-duration property indicates the length of time an animation takes to play.

 

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

 

Value

Description

time

A CSS time

 

Default Value:

0s

JavaScript syntax:

e.g. object.style.animationDuration = "5s";

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 infinite;}
div.x1 {animation-duration: 6s;}
@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.animationDuration = "6s";
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile