Simple CSS shiny progress bar technique

I’ve recently come up with a simple way to make a decent looking, css colorable progress bar/meter out of a couple divs and an image. This is what mine looks like:

Text Here!

Basically, you have three divs: a container for the grey, non ‘populated’ section, a div for the colored value, and a div for the text. Both the container and the value div have your image as a background. This image uses mad awesome png transparency to show some of the div’s background color through.

HTML

The HTML is simple:

<div class="meter-wrap">
    <div class="meter-value" style="background-color: #0a0; width: 40%;">
        <div class="meter-text">
            Text Here!
        </div>
    </div>
</div>

Notice the style attribute in the .meter-value div. The background color is the color of the progress bar, and the width is set to the percentage of progress. Easy peasy.

CSS

Oh yes, in all of its glory:

.meter-wrap{
    position: relative;
}

.meter-wrap, .meter-value, .meter-text {
    /* The width and height of your image */
    width: 155px; height: 30px;
}

.meter-wrap, .meter-value {
    background: #bdbdbd url(/path/to/your-image.png) top left no-repeat;
}
            
.meter-text {
    position: absolute;
    top:0; left:0;

    padding-top: 5px;
                
    color: #fff;
    text-align: center;
    width: 100%;
}

The Image

Here is my image. I’ve placed it on a colored background so you can see the corners. It simply has completely opaque white corners, and uses a gradient for the center that goes from transparent white to completely transparent. An image like this is very easy to construct in a vector drawing application such as Inkscape .

Examples with JavaScript!

Now, so you can see what it can do, I’ve put together a couple of super rad jQuery examples.

Click the bar below to see the it go from 0% to 100%! Coooooool!

click me!

Or maybe this one that runs through a range of colors.

click me!

Discuss

1
Rahul Bhargava  July 1, 2009 at 2:14 am

Cool this was the easiest way to achieve a static progress bar I wanted to create. Thanks

2
Kelly Smith  December 2, 2009 at 6:25 am

Thank you for this. It’s simple, yet elegant. Exactly what I needed.

3
Jon  January 2, 2010 at 1:38 pm

This is awesome. Thanks for sharing.

4
ie6user  February 10, 2010 at 1:40 am

Doesn’t work in evil browsers :-/

5
rob  February 20, 2010 at 6:29 am

where’s the js that makes the button clicks work?

6
admin  February 28, 2010 at 6:18 pm

The button click js is in an inline script element in the page source. I would post it in this comment, but WP will hose the formatting. View the source and ctrl+f for “$(’#meter-ex1′).click”.

The evil browser I am not so concerned about. ie6 has issues with png transparency. There is a jquery plugin called supersleight that can help alleviate the transparent png issues.

7
Evan  March 10, 2010 at 10:23 am

If you apply white-space: nowrap to the value and text containers it won’t wrap the text when the meter is at 0% in evil browsers. Aside from that, if you can find a good png fix this technique works great in evil browsers! Thanks!

8
Felipe Lima  June 8, 2010 at 2:48 pm

Hello,
I’ve implemented another progress bar widget as a jquery plugin based on your implementation: http://blog.felipel.com/post/JQuery-progress-bar-slider-plugin.aspx
Thought you’d like to know! :)

Felipe

9
Monte  July 29, 2010 at 9:12 am

Interesting example - is there anyway you can provide the actual image used in the demo. I’ve been trying to create the necessary image - but so far haven’t been able to create an image correctly to make the demo work.

10
Sobit  August 13, 2010 at 2:58 am

Awesome! What an excellent author’s imagination!

comment

Your email is never shared because I like you.

*
*