While playing DIRT 3, I’ve noticed a very cool triangle animation as part of their UI. Almost immediately, I thought about how to build a similar version of it using CSS3.
So, in this article you’ll see an experiment about how to create a simple CSS3 loading animation.

For this example, I’ll be using two CSS3 animations: one that fades the color for the triangles and one animation that rotates the whole design. These two animations, synchronized, will help creating a quite nice effect.
The HTML
Initially, I wanted to use pseudo-elements in order to have less markup elements. But, the thing is that generated content can’t be animated yet in other browsers than Mozilla Firefox.
Here’s how the markup looks like:
<div class="loading-wrap"> <div class="triangle1"></div> <div class="triangle2"></div> <div class="triangle3"></div> </div>
The CSS
There are some things you may find interesting here:
- For a nice color fade across all three triangles, you need to increment the animation-delay.
- Notice the gap between
20%and100%for the rotation keyframes. This helps adding a stop effect for the animation.
.loading-wrap {
width: 60px; height: 60px;
position: absolute;
top: 50%; left: 50%;
margin: -30px 0 0 -30px;
background: #777;
animation: rotation ease-in-out 2s infinite;
border-radius: 30px;
}
.triangle1, .triangle2, .triangle3 {
border-width: 0 20px 30px 20px;
border-style: solid;
border-color: transparent;
border-bottom-color: #67cbf0;
height: 0; width: 0;
position: absolute;
left: 10px; top: -10px;
animation: fadecolor 2s 1s infinite;
}
.triangle2, .triangle3 {
content: '';
top: 20px; left: 30px;
animation-delay: 1.1s;
}
.triangle3 {
left: -10px;
animation-delay: 1.2s;
}
@keyframes rotation {
0% {transform: rotate(0deg);}
20% {transform: rotate(360deg);}
100% {transform: rotate(360deg);}
}
@keyframes fadecolor {
0% {border-bottom-color: #eee;}
100%{border-bottom-color: #67cbf0;}
}
Conclusion
This is an experiment and you must be aware of it. For now, I think an animated GIF will do the job better in most of cases.
Also, this isn’t that example that advocates for using CSS3 stuff instead images to save HTTP requests. It is not applicable here as limited browser support for CSS3 animations has something to say. Though, I hope you’ll find this example useful and inspiring for your future projects.
Thanks for reading and I’m looking forward to read your opinions!
Hi Red, I’m never tired of commenting on your posts because of the sheer supreme tutorials. Once again an innovative approach towards CSS3 magic and I bet we can achieve this via jQuery too, to address cross browser compatibility.
Awesome work!
Me to while played was Dirt3 and coming my mind at first look this page ;-)
Really cool work ! Thx
Newest Opera: triangle stands still.
Currently, the browser support does not include Opera.
Try using browsers like: Chrome, Firefox (Gecko), Internet Explorer 10 or Safari.
Opera 12 can into keyframes.
Indeed, according to latest news, Opera 12 testing builds support it. Thanks for the heads up!
So… I’ll have to add one more prefixed keyframe :)
Amazing work with CSS3 animations, like your other work.
nice work.
You Awesome Man
Thank you :)
The Triforce loader, awesome !
Oh, I just googled for “Triforce” and found out about “The Legend of Zelda”. Shame on me for first seeing it in Dirt 3. :D
Nice work! Thanks a lot Red. Keep sharing. Really all your tuts are very helpful.
That’s epic. Really great job.
You are cool dude….. I have learnt a lot from your posts….. Thanks for your support….
Awesome loading animation …. Thanks for sharing.
Hi Red!
Great tutorial, and great animation! I liked it so much, I forked it and turned the triangles into circles, I hoe you do not mind… You can check it out here: http://jsfiddle.net/gnclmorais/FxGrm/
It does look interesting ;)
awesome animation…..I want to add in my free template
Thanks for sharing . Good tutorial !
That’s clearly a triforce, from the Legend of Zelda -_- But awesome tutorial!