animation-direction
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 betweennormal
andreverse
.alternate-reverse
: causes the cycles to alternate betweenreverse
andnormal
.
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
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Career path
Full-Stack Engineer
A full-stack engineer can get a project done from start to finish, back-end to front-end.Includes 51 CoursesWith Professional CertificationBeginner Friendly150 hours - Free course
Learn CSS
In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.Beginner Friendly6 hours