W3.CSS Progress Bars
What is a Progress Bar?
Progress bars show how far a task or process has progressed.
W3.CSS makes it easy to style progress bars with colors, labels, padding, and rounded corners.
Basic Progress Bar
A normal <div> element can be used for a progress bar.
Use the CSS width property to control the progress.
Example
<div class="w3-border">
<div class="w3-grey" style="height:32px;width:20%"></div>
</div>
Progress Bar Width
Change the progress with the CSS width property, from 0% to 100%:
Example
<div class="w3-light-grey">
<div class="w3-grey" style="height:24px;width:50%"></div>
</div>
Progress Bar Colors
Use w3-color classes to change the color of a progress bar:
Example
<div class="w3-light-grey">
<div class="w3-blue" style="width:75%"></div>
</div>
Progress Bar Labels
Add text inside a w3-container element to add a label to the progress bar.
Use w3-center to center the label.
Example
<div class="w3-light-grey">
<div
class="w3-container w3-green w3-center" style="width:25%">25%</div>
</div>
Progress Bar Padding
Use W3.CSS padding classes such as w3-padding-small, w3-padding, and w3-padding-large to change the height.
Example
<div class="w3-light-grey">
<div
class="w3-container w3-red w3-padding w3-center" style="width:25%">25%</div>
</div>
</div>
Progress Bar Text Size
Use W3.CSS size classes such as w3-tiny, w3-large, and w3-xlarge to change the text size:
Example
<div class="w3-light-grey w3-xlarge">
<div class="w3-container w3-green" style="width:50%">50%</div>
</div>
Rounded Progress Bars
Use w3-round classes to add rounded corners to a progress bar:
Example
<div class="w3-light-grey w3-round">
<div
class="w3-container w3-round w3-blue" style="width:25%">25%</div>
</div>
Dynamic Progress Bar
Use JavaScript to create a dynamic progress bar:
Example
<div class="w3-light-grey">
<div id="myBar" class="w3-container w3-green"
style="height:24px;width:1%"></div>
</div>
<button class="w3-button w3-light-grey" onclick="move()">Click Me</button>
<script>
function move() {
const elem =
document.getElementById("myBar");
let width =
1;
const id = setInterval(frame, 10);
function frame() {
if (width >= 100) {
clearInterval(id);
} else {
width++;
elem.style.width = width + '%';
}
}
}
</script>
Dynamic Progress Bar with Labels
Centered label:
Left-aligned label:
Label outside of the progress bar:
Another example (advanced):