/

HTML / CSS / JavaScript Tutorial

CSS Property: transition-duration

[this page | pdf | back links]

The CSS (CSS3) transition-duration property indicates how long a transition will take to complete.

 

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

 

Value

Description

time

The CSS time a transition will take to complete once started

 

Default Value:

0s

JavaScript syntax:

e.g. object.style.transitionDuration="4s"

Inherited:

No

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {width: 200px; border: 2px solid green; transition-property: width;}
p.x1 {transition-duration: 2s}
p:hover {width: 300px;}
</style>
</head>
<body>
Hover over element to see transition effect
<p>Element with default property</p>
<p class="x1">Property set using HTML</p>
<p id="x2">Property set using JavaScript</p>

<script>
document.getElementById("x2").style.transitionDuration = "2s";
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile