/

HTML / CSS / JavaScript Tutorial

CSS Property: transition

[this page | pdf | back links]

The CSS (CSS3) transition property is a shorthand property combining the 4 transition sub-properties.

 

Valid property values (other than inherit and initial) are defined by the elements of the shorthand. Shorthand elements (in the order in which they appear):

 

-        transition-property

-        transition-duration

-        transition-timing-function

-        transition-delay

 

Default Value:

See individual properties

JavaScript syntax:

e.g. object.style.transition="all 5s"

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;}
p.x1 {transition: width 2s;}
p:hover {width: 300px;}
</style>
</head>
<body>
Hover over element to see transition effect
<p class="x1">Property set using HTML</p>
<p id="x2">Property set using JavaScript</p>

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

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile