CSS Progress Bar: Custom, Animated and Native
A CSS progress bar is two boxes: a track and a fill whose width is the percentage. Below are a simple custom bar, an indeterminate “loading” bar for when you don’t know how long something takes, and how to style the native <progress> element.
Demo:
Custom progress bar
Set the fill’s width to the percentage, from your template or JavaScript. overflow: hidden on the track keeps the rounded ends clean, and a transition makes updates slide smoothly. The ARIA attributes tell screen readers the value.
<div class="progress" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" aria-label="Upload">
<div class="progress__fill" style="width: 70%"></div>
</div>
<style>
.progress { height: 12px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.progress__fill { height: 100%; background: #1d4ed8; transition: width 0.4s ease; }
</style>
Update it with JavaScript
function setProgress(el, value) {
el.setAttribute('aria-valuenow', value);
el.querySelector('.progress__fill').style.width = `${value}%`;
}
setProgress(document.querySelector('.progress'), 85);
Indeterminate loading bar
When you can’t measure progress, slide a short fill across the track in a loop. Animating transform instead of left or width keeps it smooth.
.progress--loading .progress__fill {
width: 40%;
animation: slide 1.2s ease-in-out infinite;
}
@keyframes slide {
from { transform: translateX(-100%); }
to { transform: translateX(250%); }
}
Styling the native progress element
<progress value="40" max="100"> is accessible out of the box, but it needs browser-specific pseudo-elements to style: ::-webkit-progress-bar and ::-webkit-progress-value for Chrome, Edge and Safari, and ::-moz-progress-bar for Firefox. Remove the default look with appearance: none first.
progress {
width: 100%;
height: 12px;
appearance: none;
border: 0;
border-radius: 999px;
overflow: hidden;
background: #e2e8f0;
}
progress::-webkit-progress-bar { background: #e2e8f0; }
progress::-webkit-progress-value { background: #1d4ed8; }
progress::-moz-progress-bar { background: #1d4ed8; }
FAQ
Should I use <progress> or a div?<progress> is semantic and accessible without extra attributes, but harder to style. A div gives full control; add role="progressbar" and the aria-value* attributes so it stays accessible.
How do I show the percentage inside the bar?
Put the text in the fill (or over the track with absolute positioning) and make sure it has enough contrast with both the fill and the track colors.
How do I make a circular progress bar?
Use a conic-gradient on a circle, with the angle based on the percentage, and a smaller circle on top to make it a ring.
Related: Tailwind animate-pulse, requestAnimationFrame, CSS Flexbox and HTML tips.