Back
Tutorial on how to create a simple loader using CSS.
<div class="loader"></div>
.loader { width: 3rem; height: 3rem; border-radius: 50%; border: 10px solid #000; border-color: #000 transparent; }Now we'll create an animation named "rotation". We'll simply set the transform property to rotate 0 deg on 0% and 360 deg on 100%.
@keyframes rotation { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }And now simply add the animation property on loader element. We'll set the duration of 1 second, infinite and linear.
.loader {
width: 3rem;
height: 3rem;
border-radius: 50%;
border: 10px solid #000;
border-color: #000 transparent #000 transparent;
animation: rotation 1s linear infinite; <!-- Animation -->
}
<div class="loader"></div> <style> .loader { width: 3rem; height: 3rem; border-radius: 50%; border: 10px solid #000; border-color: #000 transparent; animation: rotation 1s linear infinite; } @keyframes rotation { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } </style>Thank you for reading this article.