Labelled Linear Progress Bar With Value
A setup checklist card for a florist's new site. A title and a bold percentage sit above a thin blue bar, a line underneath says 3 of 5 steps done, and the steps below tick off as the bar fills. Two buttons move it forward and back so you can watch the fill ease into place. The card keeps its layout at phone width with the buttons side by side.
Code
import { useState } from "react";
// Setup steps: the bar shows the share that is done.
const STEPS = ["Add your logo", "Pick a colour theme", "Write the About page", "Connect a domain", "Publish"];
export default function LabelledLinearProgressBar() {
const [done, setDone] = useState(3);
const pct = Math.round((done / STEPS.length) * 100);
return (
<section className="bg-white px-4 py-16">
<div className="mx-auto max-w-lg rounded-2xl border border-slate-200 p-6 sm:p-8">
<div className="flex items-baseline justify-between gap-4">
<h2 id="lpb-label" className="text-base font-semibold text-slate-900">Site setup</h2>
<span className="text-sm font-semibold tabular-nums text-slate-900" aria-hidden="true">{pct}%</span>
</div>
<p className="mt-1 text-sm text-slate-600">{done} of {STEPS.length} steps done for Bramble & Oak Florists</p>
<div
role="progressbar"
aria-labelledby="lpb-label"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={pct}
aria-valuetext={`${pct} percent, ${done} of ${STEPS.length} steps`}
className="mt-4 h-2.5 overflow-hidden rounded-full bg-slate-100"
>
<div
className="h-full w-full origin-left rounded-full bg-blue-600 transition-transform duration-500 ease-out motion-reduce:transition-none"
style={{ transform: `scaleX(${done / STEPS.length})` }}
/>
</div>
<ol className="mt-6 space-y-1">
{STEPS.map((s, i) => (
<li key={s} className="flex h-9 items-center gap-3 text-sm">
<span className={`grid h-5 w-5 shrink-0 place-items-center rounded-full ${i < done ? "bg-blue-600" : "border-2 border-slate-300"}`} aria-hidden="true">
{i < done && <svg viewBox="0 0 12 12" width="10" height="10"><path d="M2.5 6.2l2.2 2.2 4.8-4.9" fill="none" stroke="#fff" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" /></svg>}
</span>
<span className={i < done ? "text-slate-500 line-through decoration-slate-400" : i === done ? "font-medium text-slate-900" : "text-slate-700"}>{s}</span>
<span className="sr-only">{i < done ? "done" : "to do"}</span>
</li>
))}
</ol>
<div className="mt-6 flex gap-2">
<button type="button" disabled={done >= STEPS.length} onClick={() => setDone((d) => d + 1)} className="h-10 rounded-lg bg-slate-900 px-4 text-sm font-medium text-white hover:bg-slate-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 disabled:bg-slate-200 disabled:text-slate-700">Mark next step done</button>
<button type="button" disabled={done === 0} onClick={() => setDone((d) => d - 1)} className="h-10 rounded-lg border border-slate-300 px-4 text-sm font-medium text-slate-800 hover:bg-slate-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 disabled:text-slate-500">Undo</button>
</div>
</div>
</section>
);
}
Install with one command: npx shadcn@latest add https://we.inc/r/labelled-linear-progress-bar-with-value.json
When to use it
- Showing how far someone is through onboarding, a profile or a course where the total is known.
- A dashboard tile needs a quiet bar with its number written next to it, not hidden in a tooltip.
- You want a progress bar that screen readers announce with a meaningful sentence, not only a number.
- Storage, quota or budget use, where the bar should read as a share of a fixed limit.
How to customize it
- Edit the `STEPS` array; the percentage and bar follow its length automatically.
- Change the fill colour with `bg-blue-600`, or `--lpb-accent` in the plain CSS, and the track with `bg-slate-100`.
- Make the bar thicker or thinner with `h-2.5` on the track, for example `h-1.5` for a hairline or `h-4` for a chunky bar.
- Lengthen or shorten the easing with `duration-500`; keep it under about 600 ms so updates do not lag.
Accessibility
- The track has role progressbar with aria-valuemin, aria-valuemax and aria-valuenow, and it takes its name from the Site setup heading through aria-labelledby.
- aria-valuetext adds the step count, so a screen reader says 60 percent, 3 of 5 steps rather than a bare number.
- The visible percentage is hidden from assistive technology to avoid hearing the value twice; each step also says done or to do in hidden text.
Questions
Why scale the fill instead of changing its width?
A width change makes the browser recalculate layout for the bar on every update. Scaling a full width fill along the x axis with transform-origin left looks the same but can be handled by the compositor, which keeps the motion smooth.
Does the rounded end look wrong when scaled?
At very small values the rounded right edge squashes slightly because the whole element is scaled. On a thin bar it is hard to see; if it bothers you, switch to a width style for bars that rarely update.
How do I connect it to real progress?
Replace the `done` state with your own value, from a fetch progress event, a form step or a stored profile score, and pass the fraction to the scaleX style. The ARIA values read from the same number.
Can I put the percentage inside the bar?
Only on a thick bar of 16 pixels or more, and check contrast on both the filled and empty parts, since the text crosses both as the value grows. Placing it above the bar, as here, avoids that problem.
Should I use the native progress element instead?
It works and needs no ARIA, but its fill is styled with vendor pseudo elements that differ between browsers. A div with role progressbar gives the same meaning to assistive technology with one set of styles.
Related: Percentage Counter With Progress Ring, Circular SVG Progress Ring With Percentage, File Upload List With Per File Progress Bars.
More loaders or all free UI components. Build your site free to have a full site built around it.
More in Loaders
- Mechanical Watch Movement Loader with Swinging Balance Wheel and Breathing Hairspring
- Nitro Cold Brew Tumbler Loader That Pours, Cascades and Settles Under a Cream Head
- Oil and Water Liquid Timer with Beads That Rise Through a Glass Hourglass and Flip to Restart
- Ray-Marched Hourglass Loader in a Turned Ash Frame on a Sunlit Desk That Pours Coral Sand into a Growing Cone and Flips Over When Full
- Ray-Marched Potter's Wheel Loader That Pulls Up a Wet Stoneware Bowl in a Sunlit Studio and Stops When It Is Done
- Ray-Traced Glass Pendant Loader That Fills with Glowing Liquid and Focuses a Point of Light under a Wall-Sized Percentage
- Steel Ball Bearing Loader That Drops a Ball into the Race for Every Tenth Loaded
- Banding Wheel Loader That Throws a Wet Terracotta Vase up to a Brass Height Gauge
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App