JSFiddle - React, Tailwind, and code Playground
by Mostafa Zeinivand
HTML
<div class="loader">
<svg class="circular-loader" viewBox="25 25 50 50">
<circle class="loader-path" cx="50" cy="50" r="20"></circle>
</svg>
</div>
CSS
:root {
--rotation-animation-speed: 2s;
--rotation-animation-easing: linear;
--stroke-animation-speed: 1.5s;
--stroke-animation-easing: ease-in-out;
--stroke-width: 3px;
--stroke-start-dasharray: 1, 200;
--stroke-end-dasharray: 89, 200;
--stroke-color: blue;
}
.loader {
margin: 0px auto;
width: 50px;
height: 50px;
}
.circular-loader {
animation: rotate var(--rotation-animation-speed) var(--rotation-animation-easing) infinite;
}
.loader-path {
fill: none;
stroke-width: var(--stroke-width);
animation: animate-stroke var(--stroke-animation-speed) var(--stroke-animation-easing) infinite;
stroke-linecap: round;
stroke: var(--stroke-color);
}
@keyframes rotate {
100% {
transform: rotate(360deg);
}
}
@keyframes animate-stroke {
0% {
stroke-dasharray: var(--stroke-start-dasharray);
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: var(--stroke-end-dasharray);
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: var(--stroke-end-dasharray);
stroke-dashoffset: -124;
}
}