How do you build an animated progress bar with pure CSS?
A progress bar is one of the small details that makes any page or dashboard feel polished. In this lesson you will build one with a few lines of CSS only, no external library.
Steps
- Create an outer container at full width with a light background; this is the track.
- Add an inner element for the bar itself, starting at zero width.
- Define a keyframes animation that grows the width from 0 to the target value and apply it to the bar.
- Add role="progressbar" and aria-valuenow so screen readers announce the value.
- Inside a prefers-reduced-motion media query, disable the animation and show the final value at once.
The code
HTML
<div class="progress" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar"></div>
</div>
<style>
.progress {
width: 100%;
max-width: 420px;
height: 12px;
background: #e5e7eb;
border-radius: 999px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0;
background: linear-gradient(90deg, #6d5ef0, #38bdf8);
border-radius: inherit;
animation: progress-fill 1.4s cubic-bezier(.22, .61, .36, 1) forwards;
}
@keyframes progress-fill {
to { width: 75%; }
}
@media (prefers-reduced-motion: reduce) {
.progress-bar { animation: none; width: 75%; }
}
</style>RTL & Arabic notes: the bar fills from the inline-start edge automatically, so it works in RTL with no changes.
Didn't find the motion you need? Request it from the Vellox team.