Bootstrap Progress Bars

In this tutorial you will learn how to create progress bars using Bootstrap.

Creating Progress Bar with Bootstrap

Progress bars can be used for showing the progress of a task or action to the users. The following example will show you how to create a simple progress bar with vertical gradient.

  • <div class="progress">
  •     <div class="progress-bar" style="width: 60%;">
  •         <span class="sr-only">60% Complete</span>
  •     </div>
  • </div>

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


Creating Progress Bar with Label

To show to the progress status as a percentage label just remove the <span> with .sr-only class from within the progress bar as demonstrated in example above.

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

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

If you are showing percentage label you should also add a min-width to the progress bar to ensure that the label text remains readable even for low percentage, like this.

  • <div class="progress">
  •     <div class="progress-bar" style="min-width: 20px;">
  •         0%
  •     </div>
  • </div>
  • <div class="progress">
  •     <div class="progress-bar" style="min-width: 20px; width: 2%;">
  •         2%
  •     </div>
  • </div>

Creating Stripped Progress Bar

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

  • <div class="progress progress-striped">
  •     <div class="progress-bar" style="width: 60%;">
  •         <span class="sr-only">60% Complete</span>
  •     </div>
  • </div>

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

Similarly you can create the animated progress bar — just add the .active class to .progress-stripped. The .active class animates the stripes from right to left.

  • <div class="progress progress-striped active">
  •     <div class="progress-bar" style="width: 60%;">
  •         <span class="sr-only">60% Complete</span>
  •     </div>
  • </div>
 

Warning:Due to lack of support for CSS3 animation properties the animated progress bar is not supported in any versions of IE upto IE9. Whereas, the stripped progress bar uses CSS3 gradient to create the striped effect which is not supported in IE7-8.


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.

  • <!-- Progress bar HTML -->
  • <div class="progress progress-striped active">
  •     <div class="progress-bar"></div>
  • </div>
  •  
  • <!-- jQuery Script -->
  • <script type="text/javascript">
  •     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 bars into the same progress bar to stack them.

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

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


Progress Bars with Emphasis Classes

Bootstrap also provides some emphasis utility classes for progress bars that can be further used to convey meaning through color.

  • <div class="progress">
  •     <div class="progress-bar progress-bar-info" style="width: 20%">
  •         <span class="sr-only">20% Used</span>
  •     </div>
  • </div>
  • <div class="progress">
  •     <div class="progress-bar progress-bar-success" style="width: 40%">
  •         <span class="sr-only">40% Used</span>
  •     </div>
  • </div>
  • <div class="progress">
  •     <div class="progress-bar progress-bar-warning" style="width: 80%">
  •         <span class="sr-only">80% Used</span>
  •     </div>
  • </div>
  • <div class="progress">
  •     <div class="progress-bar progress-bar-danger" style="width: 90%">
  •         <span class="sr-only">90% Used</span>
  •     </div>
  • </div>

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


Striped Progress Bars with Emphasis Classes

Similar to the solid colors, you can also create varied striped progress bars.

  • <div class="progress progress-striped">
  •     <div class="progress-bar progress-bar-info" style="width: 20%">
  •         <span class="sr-only">20% Used</span>
  •     </div>
  • </div>
  • <div class="progress progress-striped">
  •     <div class="progress-bar progress-bar-success" style="width: 40%">
  •         <span class="sr-only">40% Used</span>
  •     </div>
  • </div>
  • <div class="progress progress-striped">
  •     <div class="progress-bar progress-bar-warning" style="width: 80%">
  •         <span class="sr-only">80% Used</span>
  •     </div>
  • </div>
  • <div class="progress progress-striped">
  •     <div class="progress-bar progress-bar-danger" style="width: 90%">
  •         <span class="sr-only">90% Used</span>
  •     </div>
  • </div>

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

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.