Progress Bar
UI Coding
Easy
15 min
accessibility
css
design-system
Build a reusable ProgressBar component, then use it in a small demo.
Requirements
ProgressBaracceptsvalue(a number), an optionalmax(default100) and alabel.- The filled part's width shows
value / maxas a percentage. The percentage is also printed as text inside or next to the bar, rounded to a whole number ("42%"). - Clamp out-of-range values: anything below 0 shows as 0% and anything above
maxshows as 100%. - Accessibility: expose it as a progress bar with
role="progressbar",aria-valuenow,aria-valuemin,aria-valuemaxand an accessible name fromlabel. - If
valueisnullorundefined, render an indeterminate bar (an animated stripe) with noaria-valuenow. - The demo
Appshows a bar with −10% and +10% buttons that change its value, starting at 30%.
Follow-up
- Why not just use the native
<progress>element? - Animate the width smoothly. Which CSS property should you animate, and why?
- How would a screen-reader user learn that the progress changed?
Spotted a mistake or a rights concern? Report an issue