/

HTML / CSS / JavaScript Tutorial

CSS Property: animation-name

[this page | pdf | back links]

The CSS (CSS3) animation-name property specifies the name of an animation used in a @keyframes animation.

 

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

 

Value

Description

keyframename

Specifies name of the keyframe you want to bind to the selector

none

(default value). Indicates no animation

 

Default Value:

none

JavaScript syntax:

e.g. object.style.animationName = "myanimation";

Inherited:

No

Animatable:

No

 

The keyframes format is e.g.:

 

@keyframes myanimation {

    from { starting style }

    to { ending style }

}

 

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: 2s infinite;}
div.x1 {animation-name: anim1;}
@keyframes anim1 {from {left: 0px} to {left: 50px;} } 
@keyframes anim2 {from {left: 50px} to {left: 0px;} } 
</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.animationName = "anim2";
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile