How to Rotate an image infinitely using only CSS

Rotating an element in HTML using CSS is pretty simple, really. Add the following CSS to the element that you want to rotate.

1
animation: spin 2s infinite;

Now, in the same CSS file, create a @keyframe

1
2
3
4
5
6
7
8
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

Combining all this into one block, we get the following:

1
<div class="rotate"><div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.rotate {
margin: 40px;
width: 90px;
height: 90px;
background-color: #cc2a41;
animation: spin 2s infinite;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}