cssanimationwebkit

CSS endless rotation animation


I want to make a rotation of my loading icon by CSS.

I have an icon and the following code:

<style>
#test {
    width: 32px;
    height: 32px;
    background: url('refresh.png');
}

.rotating {
    -webkit-transform: rotate(360deg);
    -webkit-transition-duration: 1s;
    -webkit-transition-delay: now;
    -webkit-animation-timing-function: linear;
    -webkit-animation-iteration-count: infinite;
}
</style>

<div id='test' class='rotating'></div>

But it doesn't work. How can the icon be rotated using CSS?


Solution

  • Works in all modern browsers

    .rotate{
     animation: loading 3s linear infinite;
     @keyframes loading {
      0% { 
        transform: rotate(0); 
      }
      100% { 
        transform: rotate(360deg);
      }
     }
    }