Progress bars show how much of a task is done. They help people see progress easily.
Progress bars in Bootsrap
<div class="progress"> <div class="progress-bar" role="progressbar" style="width: 50%;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> </div>
role="progressbar" and aria-* attributes for accessibility.style="width: X%;" controls how much the bar fills.<div class="progress"> <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div> </div>
bg-success color.<div class="progress"> <div class="progress-bar bg-success" role="progressbar" style="width: 75%;" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div> </div>
<div class="progress"> <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 60%;" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"></div> </div>
This example shows three progress bars with different styles and progress levels. Each bar uses Bootstrap classes for color, stripes, and animation. The text inside the bar shows the percentage done. The aria-label on sections helps screen readers understand the purpose.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Progress Bars Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container mt-5"> <h1>Progress Bars Demo</h1> <section aria-label="File upload progress"> <p>File upload progress:</p> <div class="progress" style="height: 1.5rem;"> <div class="progress-bar bg-info progress-bar-striped progress-bar-animated" role="progressbar" style="width: 40%;" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100">40%</div> </div> </section> <section aria-label="Form completion progress" class="mt-4"> <p>Form completion:</p> <div class="progress" style="height: 1.5rem;"> <div class="progress-bar bg-success" role="progressbar" style="width: 80%;" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100">80%</div> </div> </section> <section aria-label="Loading progress" class="mt-4"> <p>Loading progress:</p> <div class="progress" style="height: 1.5rem;"> <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 55%;" aria-valuenow="55" aria-valuemin="0" aria-valuemax="100">55%</div> </div> </section> </main> </body> </html>
Always include aria-valuenow, aria-valuemin, and aria-valuemax for accessibility.
Use progress-bar-striped and progress-bar-animated classes to add visual interest.
Adjust the width style to change the progress amount.
Progress bars visually show how much of a task is done.
Bootstrap makes it easy to create styled and accessible progress bars.
Use colors, stripes, and animation to make progress bars clearer and nicer.
Practice
progress bar in Bootstrap?Solution
Step 1: Understand the role of progress bars
Progress bars are used to show progress visually, like filling a bar as a task advances.Step 2: Match the purpose with options
Only To visually show how much of a task is completed describes showing task completion visually, which is the purpose of progress bars.Final Answer:
To visually show how much of a task is completed -> Option DQuick Check:
Progress bar = Visual task progress [OK]
- Confusing progress bars with buttons or links
- Thinking progress bars display images
- Mixing progress bars with navigation elements
Solution
Step 1: Identify the container class for progress bars in Bootstrap
The container that holds the progress bar isprogress, notprogress-barwhich is the inner bar.Step 2: Check each option
<div class='progress'></div>usesprogresswhich is correct. The other options use incorrect or non-existent classes.Final Answer:
<div class='progress'></div> -> Option AQuick Check:
Container class = progress [OK]
- Using 'progress-bar' as container instead of inner bar
- Inventing class names like 'bar-progress'
- Confusing container and inner bar classes
<div class='progress'> <div class='progress-bar bg-success' role='progressbar' style='width: 75%;'>75%</div> </div>
Solution
Step 1: Analyze the classes and styles
The inner div has classprogress-barandbg-successwhich makes it green. The style sets width to 75%.Step 2: Understand the visual output
The bar will fill 75% of the container width in green color and show the text '75%'.Final Answer:
A green progress bar filled to 75% with text '75%' inside -> Option BQuick Check:
bg-success + width 75% = green bar 75% filled [OK]
- Confusing bg-success with red color
- Ignoring the style width property
- Expecting 100% fill without style
<div class='progress'> <div class='progress-bar' role='progressbar' style='width: 50%;>50%</div> </div>
Solution
Step 1: Check the style attribute syntax
The style attribute isstyle='width: 50%;>which misses the closing single quote before the closing angle bracket.Step 2: Verify other attributes
Classprogress-barand role attribute are correct. Width 50% is valid.Final Answer:
Missing closing quote in style attribute -> Option AQuick Check:
Style attribute quotes must close properly [OK]
- Ignoring missing quote causing HTML error
- Thinking class 'progress-bar' is wrong
- Assuming role attribute is optional but not error
Solution
Step 1: Identify correct Bootstrap classes for striped and animated bars
The correct classes areprogress-bar-stripedandprogress-bar-animated. The color class for blue isbg-primary.Step 2: Check each option's class usage and structure
<div class='progress'><div class='progress-bar bg-primary progress-bar-striped progress-bar-animated' role='progressbar' style='width: 40%;'>40%</div></div>uses all correct classes and structure inside aprogresscontainer. The other options use incorrect or missing class names or wrong container structure.Final Answer:
<div class='progress'><div class='progress-bar bg-primary progress-bar-striped progress-bar-animated' role='progressbar' style='width: 40%;'>40%</div></div> -> Option CQuick Check:
Striped + animated classes = progress-bar-striped + progress-bar-animated [OK]
- Using incorrect class names like 'striped' or 'progress-striped'
- Missing the container div with class 'progress'
- Placing classes on wrong elements
Ready to prove it?
Pass the test and this pattern moves unknown
