CSSJavaScriptPythonReact-Native
thumbnail image

Loading spinner in pure css

By Manas Makde
<div class="spinner"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div>
.spinner { --radius:4rem; --bar_length:1rem; --bar_thickness:0.35rem; --bar_border_radius:5px; --speed: 0.1s; --bar_color:dodgerblue; height: var(--radius); width: var(--radius); position: relative; display: flex; justify-content: center; align-items: center; } .spinner div { position: absolute; display: flex; justify-content: center; height: 100%; } .spinner div::before, .spinner div::after { content: ''; display: block; height: var(--bar_length); width: var(--bar_thickness); background-color: var(--bar_color); position: absolute; border-radius:var(--bar_border_radius); animation: spinning calc(var(--speed) * 12) linear infinite; } .spinner div::after{ bottom: 0; } .spinner div:nth-child(1) { transform: rotate(-30deg); } .spinner div:nth-child(1)::before { animation-delay: calc(var(--speed) * -7); } .spinner div:nth-child(1)::after { animation-delay: calc(var(--speed) * -1); } .spinner div:nth-child(2) { transform: rotate(-60deg); } .spinner div:nth-child(2)::before { animation-delay: calc(var(--speed) * -8); } .spinner div:nth-child(2)::after { animation-delay: calc(var(--speed) * -2); } .spinner div:nth-child(3) { transform: rotate(-90deg); } .spinner div:nth-child(3)::before { animation-delay: calc(var(--speed) * -9); } .spinner div:nth-child(3)::after { animation-delay: calc(var(--speed) * -3); } .spinner div:nth-child(4) { transform: rotate(-120deg); } .spinner div:nth-child(4)::before { animation-delay: calc(var(--speed) * -10); } .spinner div:nth-child(4)::after { animation-delay: calc(var(--speed) * -4); } .spinner div:nth-child(5) { transform: rotate(-150deg); } .spinner div:nth-child(5)::before { animation-delay: calc(var(--speed) * -11); } .spinner div:nth-child(5)::after { animation-delay: calc(var(--speed) * -5); } .spinner div:nth-child(6) { transform: rotate(-180deg); } .spinner div:nth-child(6)::before { animation-delay: calc(var(--speed) * -12); } .spinner div:nth-child(6)::after { animation-delay: calc(var(--speed) * -6); } @keyframes spinning{ 0% { opacity: 1; } 100% { opacity: 0; } }
$radius: 4rem; $bar_color: dodgerblue; $bar_length: 1rem; $bar_thickness: 0.35rem; $bar_border_radius: 5px; $speed: 0.1s; .spinner { height: $radius; width: $radius; display: flex; justify-content: center; align-items: center; position: relative; div { position: absolute; display: flex; justify-content: center; height: 100%; &::before, &::after { content: ''; display: block; height: $bar_length; width: $bar_thickness; background-color: $bar_color; position: absolute; border-radius:$bar_border_radius; animation: spinning $speed*12 linear infinite; } &::after{ bottom: 0; } @for $i from 1 through 6 { &:nth-child(#{$i}) { transform: rotate(-30deg * $i); &::before{ animation-delay: $speed * ($i + 6) * -1; } &::after{ animation-delay: $speed * $i * -1; } } } } } @keyframes spinning{ 0% { opacity: 1; } 100% { opacity: 0; } }