written on:27 Mar, 2008 by Alen Grakalic
Pure CSS Animated Progress Bar
Delicious | Digg | Stumble | Reddit | Float | Subscribe to RSS Feed
Here's a simple demonstration of how you can create animated progress bar using pure css. The trick is very simple. We need 3 elements, one container and 2 nested elements.
Take a look at the demo | Download zip file
The Concept
We'll put a cool background image in the container and define fixed width and height. First child (SPAN) will act as a progress bar. We'll absolutely position second child (EM) above the progress bar and shift it to the left to a desired value. EM has the same background as the container so it gives an effect of progress bar stopping at certain percentage.

Markup
To keep it as meaningful as possible I used definition list (DL) to list for several values. For single progress bar you can use any element you want. I love paragraphs so I used P in my example.
<dd> <span><em style="left:100px">50%</em></span> </dd>
I decided to use inline styles for left EM placement. It is more convenient to write both values at the same place at once.
Animation
How is it done? Using animated gif of course. Remember those? SPAN has a 200px wide background gif that animates from "zero" to 200px. No matter what percentage we use it goes all the way and stops. Effect of stopping at certain percentage is done with EM as I mentioned earlier.
EM placement
In my example I use 200 pixels wide progress bar. EM element is also 200px wide. So each percentage is 2px wide. If we want to accurately shift the EM we need to multiply percentages with 2.
i.e. 50% will mean 100px left offset, 24% will mean 48px offset, 75% - 150px etc. You get the picture. :)
About the author:
Designer, developer and a passionate standardista with large experience in all types of front-end work. Started to get involved with web in 1999. and turned freelance in 2005., the same year he started Css Globe. Alen's work has been featured on numerous css galleries including famous Css Zen Garden official list. Available for contract work.
Enjoyed the article?
Subscribe to our RSS feed or share it with your friends.
Delicious | Digg | Stumble | Reddit | Float | Subscribe to RSS Feed

Catar4x on 27 Mar, 2008 wrote:
With only CSS !
Thanks a lot for the script ;)
henri - blog webdesign on 27 Mar, 2008 wrote:
Yves on 27 Mar, 2008 wrote:
But there is still one thing : Is it usefull ? I don't realy think so, you can't calculate any real progression if you have to. And it's very intrusive ... But hey well done !
Peter on 28 Mar, 2008 wrote:
1. what kind of progress bar is it when you cannot control it's progress (once displayed)
2. incorrect usage of definition list, ex: the definition of "Ability to annoy people" is not 80%
cssglobe on 28 Mar, 2008 wrote:
@Peter: Not sure what you mean with incorrect usage if DL? Why exaclty would this be incorrect?
fwolf on 28 Mar, 2008 wrote:
cu, w0lf.
GUESS on 28 Mar, 2008 wrote:
BTM on 30 Mar, 2008 wrote:
cssglobe on 30 Mar, 2008 wrote:
fedmich on 30 Mar, 2008 wrote:
Mauro De Giorgi on 31 Mar, 2008 wrote:
Markavian on 31 Mar, 2008 wrote:
Using CSS for image simple manipulation (cropping), like with rollover buttons, and other tricks is a great way to make clean and simple tweaks at the CSS/HTML level without having to reload your graphics editor. I don't think I can see a use for this one though- I'd sooner use javascript to set the values dynamically, and default to a plain-filled results bar if javascript was disabled.
Simon Gow on 31 Mar, 2008 wrote:
this could also be easily modifiable by javascript which makes it cool!
Quevin on 31 Mar, 2008 wrote:
Muralikrishna on 2 Apr, 2008 wrote:
Carlos Fernando Benitez Zapata on 2 Apr, 2008 wrote:
Carlos Fernando Benitez Zapata on 2 Apr, 2008 wrote:
vincent Voyer on 3 Apr, 2008 wrote:
There's nothing but 2 html tags, an animated gif, and the overflow:hidden property here ...
This is not css related but all about animated Gifs.
You should have done something better with small jquery script + 1px width png non animated transparent image + a little html markup (like ) + make the strong and span width to 0 with css + add a background color to the span + add your background image to the strong + launch script !
Ok this is not pure CSS but at least it's not just an animated gif.
cssglobe on 3 Apr, 2008 wrote:
And it's not just animated gif either... I am using one more element placed ABOVE the animated gif, that is faking the end of progress movement.
Quoka on 4 Apr, 2008 wrote:
div {
width:216px;height:41px;padding: 5px;
background:url(http://cssglobe.com/lab/progress_bar/bg_bar.gif) no-repeat 0 0;
}
div div {
margin: 3px;text-indent:-8000px;
background:url(http://cssglobe.com/lab/progress_bar/bar.gif) no-repeat 0 0;
width: 80%;
}
Quoka on 4 Apr, 2008 wrote:
Quoka on 4 Apr, 2008 wrote:
(div) (div) 80% (/div) (/div)
Rafael Masoni on 5 Apr, 2008 wrote:
Congratulations!
gwinn on 7 Apr, 2008 wrote:
Micael on 9 Apr, 2008 wrote:
Very good.
Congratulations.
Herbalife on 11 Apr, 2008 wrote:
Jay on 12 Apr, 2008 wrote:
Tanguy on 16 Apr, 2008 wrote:
I love this progress bar, good job. But i would like to do with different color of bar and it's a big job to change or create a new bar with another color.
Thanks a lot for your job.
Max on 20 Apr, 2008 wrote:
And then you say, hey, what about ppl who dont have the flash player plugin? Come on! Who dont have it! Btw, you can even publish your animation on flash4
David Blanchet on 24 Apr, 2008 wrote:
cssglobe on 25 Apr, 2008 wrote:
Nima Fatemi on 3 May, 2008 wrote:
John Faulds on 5 May, 2008 wrote:
Seb on 9 May, 2008 wrote:
Web address: www.sebruiz.com
Arun on 14 May, 2008 wrote:
Jack Neary on 16 May, 2008 wrote:
Well done.
sotec software on 21 May, 2008 wrote:
Jeremy on 22 May, 2008 wrote:
Stoik on 24 May, 2008 wrote:
cam filmi on 1 Jun, 2008 wrote:
Jon on 4 Jun, 2008 wrote:
Nice experiment, but not useful.
niladri on 20 Jun, 2008 wrote:
Subscribe
Join 4700+ subscribers and receive our content instantly.
Subscribe to our feed
Follow us on Twitter
Want to be the first to know when a new article is published?
Follow us on Twitter
Sponsors
PSD to HTML
Smashing Jobs
Look Professional with FreshBooks
FlashDen - The Best Flash Files
Sitegrinder 2 Photoshop Plugin
PSD to HTML
Convert Design to XHTML/CSS
RF Image Subscriptions from $79
Online Bookmark Manager
Advertise here
Recent Articles
Recent Community News