Set whether an animation should be played forwards or using CSS


Use the animation-direction property to set whether an animation should be played forwards, backward or in alternate cycles:

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 200px;
            background-color: yellow;
            animation-name: myanim;
            animation-duration: 2s;
            animation-direction: reverse;
         }
         @keyframes myanim {
            from {
               background-color: green;
            }
            to {
               background-color: blue;
            }
         }
      </style>
   </head>
   <body>
      <div></div>
   </body>
</html>

Updated on: 24-Jun-2020

70 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements