Setting the Height of Progress Bars


The default height of the progress-bar is 16px, but you can also set its height according to your need by setting the CSS height property on the .progress element, like this:

Example

<!-- Progress bar with 2px height -->
<div class="progress" style="height: 2px;">
    <div class="progress-bar" style="width: 50%;"></div>
</div>
<!-- Progress bar with 20px height -->
<div class="progress" style="height: 20px;">
    <div class="progress-bar" style="width: 50%;"></div>
</div>

— The output of the above example will look something like this:

Bootstrap Progress Bar Height Sizing

Creating Stripped Progress Bar

To create the stripped progress bar just add an extra class .progress-bar-striped to the .progress-bar element, as shown in the following example:

Example

<div class="progress">
    <div class="progress-bar progress-bar-striped" style="width: 60%;"></div>
</div>

— The output of the above example will look something like this:

Bootstrap Stripped Progress Bar

Tip: The stripe is generated via CSS gradient over the progress bar’s background color. See the tutorial on CSS3 Gradients to learn how to create gradient colors using CSS.

Creating Animated Progress Bar

You can also animate the stripped progress-bar. Add the class .progress-bar-animated to the .progress-bar element, it will animate the stripes from right to left via CSS3 animations.

Example

<div class="progress">
    <div class="progress-bar progress-bar-striped progress-bar-animated" style="width: 60%"></div>
</div>

Changing Progress Bar Value Dynamically

Static progress bars aren’t very impressive. The following example will give you a rough idea of how to update the status of a Bootstrap progress bar dynamically using jQuery.

Example

jQuery JavaScript

<script>
var i = 0;
function makeProgress(){
    if(i < 100){
        i = i + 1;
        $(".progress-bar").css("width", i + "%").text(i + "%");
    }

    // Wait for sometime before running this script again
    setTimeout("makeProgress()", 100);
}
makeProgress();
</script>

Creating Stacked Progress Bar

You can also place multiple progress bars in a progress component to stack them.

Here’s an example that demonstrates how it actually works.

Example

<div class="progress">
    <div class="progress-bar bg-success" style="width: 40%">
        Program Files (40%)
    </div>
    <div class="progress-bar bg-warning" style="width: 25%">
        Residual Files (25%)
    </div>
    <div class="progress-bar bg-danger" style="width: 15%">
        Junk Files (15%)
    </div>
</div>

— The output of the above example will look something like this:

Bootstrap Stacked Progress Bar

Creating Progress Bars of Different Colors

You can additionally use background color utility classes to create progress bars of various colors in order to convey meaning through color, as shown in the following example:

Example

<div class="progress">
    <div class="progress-bar bg-info" style="width: 20%"></div>
</div>
<div class="progress">
    <div class="progress-bar bg-success" style="width: 40%"></div>
</div>
<div class="progress">
    <div class="progress-bar bg-warning" style="width: 80%"></div>
</div>
<div class="progress">
    <div class="progress-bar bg-danger" style="width: 90%"></div>
</div>

— The output of the above example will look something like this:

Bootstrap Progress Bar with Emphasis

Leave a Reply

Your email address will not be published. Required fields are marked *