Pure CSS loading animation
I wanted to create a nice little loading animation that wasn’t your stock-standard animated GIF. Below is my result. I leveraged some CSS3 keyframe animations along with border-radius properties to achieve the overall effect.
I’ve shared this little snippet on gist and codepen.io if you’d like to have a look around these great sites as well.
HTML
<div class="loading-container"> <div class="loading"></div> <div id="loading-text">loading</div> </div>
CSS
@-moz-keyframes rotate-loading { 0% {transform: rotate(0deg);-ms-transform: rotate(0deg); -webkit-transform: rotate(0deg); -o-transform: rotate(0deg); -moz-transform: rotate(0deg);} 100% {transform: rotate(360deg);-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); -o-transform: rotate(360deg); -moz-transform: rotate(360deg);} } @-o-keyframes rotate-loading { 0% {transform: rotate(0deg);-ms-transform: rotate(0deg); -webkit-transform: rotate(0deg); -o-transform: rotate(0deg); -moz-transform: rotate(0deg);} 100% {transform: rotate(360deg);-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); -o-transform: rotate(360deg); -moz-transform: rotate(360deg);} } @-webkit-keyframes rotate-loading { 0% {transform: rotate(0deg);-ms-transform: rotate(0deg); -webkit-transform: rotate(0deg); -o-transform: rotate(0deg); -moz-transform: rotate(0deg);} 100% {transform: rotate(360deg);-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); -o-transform: rotate(360deg); -moz-transform: rotate(360deg);} } @keyframes rotate-loading { 0% {transform: rotate(0deg);-ms-transform: rotate(0deg); -webkit-transform: rotate(0deg); -o-transform: rotate(0deg); -moz-transform: rotate(0deg);} 100% {transform: rotate(360deg);-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); -o-transform: rotate(360deg); -moz-transform: rotate(360deg);} } @-moz-keyframes loading-text-opacity { 0% {opacity: 0} 20% {opacity: 0} 50% {opacity: 1} 100%{opacity: 0} } @-o-keyframes loading-text-opacity { 0% {opacity: 0} 20% {opacity: 0} 50% {opacity: 1} 100%{opacity: 0} } @-webkit-keyframes loading-text-opacity { 0% {opacity: 0} 20% {opacity: 0} 50% {opacity: 1} 100%{opacity: 0} } @keyframes loading-text-opacity { 0% {opacity: 0} 20% {opacity: 0} 50% {opacity: 1} 100%{opacity: 0} } .loading-container, .loading { height: 100px; position: relative; width: 100px; border-radius: 100%; } .loading-container { margin: 40px auto; } .loading { border: 2px solid transparent; border-color: transparent #fff transparent #FFF; -moz-animation: rotate-loading 1.5s linear 0s infinite normal; -moz-transform-origin: 50% 50%; -o-animation: rotate-loading 1.5s linear 0s infinite normal; -o-transform-origin: 50% 50%; -webkit-animation: rotate-loading 1.5s linear 0s infinite normal; -webkit-transform-origin: 50% 50%; animation: rotate-loading 1.5s linear 0s infinite normal; transform-origin: 50% 50%; } .loading-container:hover .loading { border-color: transparent #E45635 transparent #E45635; } .loading-container:hover .loading, .loading-container .loading { -webkit-transition: all 0.5s ease-in-out; -moz-transition: all 0.5s ease-in-out; -ms-transition: all 0.5s ease-in-out; -o-transition: all 0.5s ease-in-out; transition: all 0.5s ease-in-out; } #loading-text { -moz-animation: loading-text-opacity 2s linear 0s infinite normal; -o-animation: loading-text-opacity 2s linear 0s infinite normal; -webkit-animation: loading-text-opacity 2s linear 0s infinite normal; animation: loading-text-opacity 2s linear 0s infinite normal; color: #ffffff; font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif; font-size: 10px; font-weight: bold; margin-top: 45px; opacity: 0; position: absolute; text-align: center; text-transform: uppercase; top: 0; width: 100px; }
https://www.domsammut.com/?p=382#comment-2019
#Mae
Thank you so muuucch! This helps me a lot! Saw this post in codepen!
Hey guys. after adding the css.
you can add the below js script so it will fadeout.
$(window).load(function(){
$(‘.loading-container’).fadeOut(1000);
});
https://www.domsammut.com/?p=382#comment-2103
#alfred
I added it but it does not work
https://www.domsammut.com/?p=382#comment-1772
#Jose
Hi, im trying to use this, but is not working on my page, it just appear “loading” on a row and it don’t disappear.
https://www.domsammut.com/?p=382#comment-1773
#Dom Sammut
Hi Jose,
This CSS animation isn’t actually loading anything. It is just a demonstration. When implemented in a proper environment this animation would work in conjunction with some javascript or other method to control when it appears / disappears.
Cheers
Dom
https://www.domsammut.com/?p=382#comment-102
#noisysymphony
rad