Bootstrap Progress Bars
Learn how to create progress bars in Bootstrap to display the completion status of tasks, downloads, uploads, and projects.
What are Progress Bars?
A progress bar is a visual component that shows how much of a task has been completed.
For example, if a task is 60% complete, the progress bar displays 60% of its total width as filled.
Why Use Progress Bars?
Progress bars help users understand the status of an ongoing task.
- Display course completion percentages.
- Show file upload or download progress.
- Track project completion.
- Display the progress of a form or installation.
Basic Progress Bar
Bootstrap uses the .progress class
as the progress bar container and
.progress-bar for the filled portion.
Example:
Code:
<div class="progress"
role="progressbar"
aria-valuenow="60"
aria-valuemin="0"
aria-valuemax="100">
<div class="progress-bar" style="width: 60%">
60%
</div>
</div>
width: 60% property fills 60% of the
progress bar. The remaining 40% stays unfilled.
Progress Bar Colors
Bootstrap provides background utility classes to change the color of a progress bar.
Example:
Primary
Success
Warning
Danger
<div class="progress">
<div class="progress-bar bg-primary"
style="width: 70%">
70%
</div>
</div>
<div class="progress">
<div class="progress-bar bg-success"
style="width: 80%">
80%
</div>
</div>
<div class="progress">
<div class="progress-bar bg-danger"
style="width: 30%">
30%
</div>
</div>
bg-primary, bg-success,
bg-warning, and bg-danger
apply different colors to the filled bar.
Progress Bar Height
You can change the height of a progress bar using CSS.
Example:
Small Height
Default Height
Large Height
<div class="progress" style="height: 30px;">
<div class="progress-bar bg-success"
style="width: 60%">
60%
</div>
</div>
height property changes the total
height of the progress bar.
Progress Bar with Label
You can display the completion percentage inside the progress bar.
Example:
<div class="progress">
<div class="progress-bar bg-success"
style="width: 85%">
85% Complete
</div>
</div>
Striped Progress Bars
Add the .progress-bar-striped class
to display diagonal stripes on the progress bar.
Example:
<div class="progress">
<div class="progress-bar progress-bar-striped bg-primary"
style="width: 65%">
65%
</div>
</div>
.progress-bar-striped class adds
a striped design. It does not automatically animate
the progress.
Animated Progress Bars
Add .progress-bar-animated along with
.progress-bar-striped to animate the
stripes.
Example:
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-success"
style="width: 75%">
75%
</div>
</div>
Multiple Progress Bars
You can place multiple progress bars inside one progress container to show different parts of a task.
Example:
<div class="progress">
<div class="progress-bar bg-success"
style="width: 40%">
40%
</div>
<div class="progress-bar bg-info"
style="width: 30%">
30%
</div>
<div class="progress-bar bg-warning"
style="width: 30%">
30%
</div>
</div>
Real-World Example
A training institute can use progress bars to display the completion status of different courses.
Important Bootstrap Progress Bar Classes
| Class | Purpose |
|---|---|
.progress |
Creates the progress bar container. |
.progress-bar |
Creates the filled progress section. |
.bg-success |
Applies a green background. |
.bg-primary |
Applies the primary background color. |
.progress-bar-striped |
Adds diagonal stripes. |
.progress-bar-animated |
Animates the striped effect. |
style="width: 60%" |
Sets the filled portion to 60%. |
Common Mistakes
-
Forgetting the
.progresscontainer. -
Forgetting the
.progress-barclass. - Using an incorrect width percentage.
- Assuming an animated progress bar automatically increases its percentage.
-
Forgetting accessibility attributes such as
aria-valuenow,aria-valuemin, andaria-valuemax.
Summary
Bootstrap Progress Bars visually display the completion status of a task.
-
.progresscreates the container. -
.progress-barcreates the filled section. -
The CSS
widthproperty sets the percentage. - Background classes change the progress bar color.
-
.progress-bar-stripedadds stripes. -
.progress-bar-animatedanimates the stripes. - JavaScript or application logic is needed to update progress dynamically.