CSS animation-direction
Anonymous contributor
Published Jul 1, 2021Updated May 15, 2024
Contribute to Docs
Determines whether an animation runs forward or in reverse on some or all of its cycles.
Syntax
animation-direction: <value>;
where <value> can be one of the following:
normal: Animation will play as specified.reverse: Animation will be played in the reverse direction as specified.alternate: causes the cycles to alternate betweennormalandreverse.alternate-reverse: causes the cycles to alternate betweenreverseandnormal.
Example 1
Reverse the direction of the animation:
div {height: 200px;width: 200px;background-color: blue;animation-name: slideleft;animation-duration: 4s;animation-direction: reverse;}@keyframes slideleft {from {margin-left: 100%;}to {margin-left: 0%;}}

Example 2
Set the first direction to alternate and the second direction to alternate-reverse:
div {height: 200px;width: 200px;background-color: blue;animation-name: fadeout, slideright;animation-duration: 4s, 4000ms;animation-iteration-count: 2;animation-direction: alternate, alternate-reverse;}@keyframes fadeout {from {background-color: blue;}to {background-color: white;}}@keyframes slideright {from {margin-left: 0%;}to {margin-left: 100%;}}

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn CSS on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- A full-stack engineer can get a project done from start to finish, back-end to front-end.
- Includes 51 Courses
- With Professional Certification
- Beginner Friendly.150 hours