Progress Bars
<div class="progress" role="progressbar" aria-label="Uploading" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100">
<span style="width: 66%"></span>
</div>
The markup is a track and a span for each part
The span's inline width is its part of the track. A track for one value is a role="progressbar" with aria-valuenow.
<div class="progress" role="progressbar" aria-label="Uploading" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100">
<span style="width: 66%"></span>
</div>
data-size on the track sets the height: sm 4px, none 6px, lg 12px, xl 32px
<div class="flex flex-col gap-5">
<div class="progress" role="progressbar" aria-label="Small, 4 of 6 steps done" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100" data-size="sm">
<span style="width: 66%"></span>
</div>
<div class="progress" role="progressbar" aria-label="Default, 4 of 6 steps done" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100">
<span style="width: 66%"></span>
</div>
<div class="progress" role="progressbar" aria-label="Large, 4 of 6 steps done" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100" data-size="lg">
<span style="width: 66%"></span>
</div>
<div class="progress" role="progressbar" aria-label="Extra large, 4 of 6 steps done" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100" data-size="xl">
<span style="width: 66%"></span>
</div>
</div>
data-variant on a span sets its colour: none is primary, then success, warning, info and destructive
<div class="flex flex-col gap-5">
<div class="progress" role="progressbar" aria-label="Primary" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100">
<span style="width: 45%"></span>
</div>
<div class="progress" role="progressbar" aria-label="Storage used" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100">
<span style="width: 30%" data-variant="success"></span>
</div>
<div class="progress" role="progressbar" aria-label="Storage used" aria-valuenow="78" aria-valuemin="0" aria-valuemax="100">
<span style="width: 78%" data-variant="warning"></span>
</div>
<div class="progress" role="progressbar" aria-label="Sync progress" aria-valuenow="55" aria-valuemin="0" aria-valuemax="100">
<span style="width: 55%" data-variant="info"></span>
</div>
<div class="progress" role="progressbar" aria-label="Storage used" aria-valuenow="96" aria-valuemin="0" aria-valuemax="100">
<span style="width: 96%" data-variant="destructive"></span>
</div>
</div>
A label and the value above the track
Storage
7.8 GB of 10 GB
<div class="flex flex-col gap-2">
<div class="flex items-center justify-between text-sm">
<span id="demo-progress-storage-label" class="font-medium">Storage</span>
<span class="text-muted-foreground">7.8 GB of 10 GB</span>
</div>
<div class="progress" role="progressbar" aria-labelledby="demo-progress-storage-label" aria-valuenow="78" aria-valuemin="0" aria-valuemax="100" aria-valuetext="7.8 GB of 10 GB">
<span style="width: 78%" data-variant="warning"></span>
</div>
</div>
Several spans divide the track between them
<div class="progress" data-size="lg" role="img" aria-label="Orders by fulfillment: 62% fulfilled, 23% processing, 15% unfulfilled">
<span style="width: 62%"></span>
<span style="width: 23%"></span>
<span style="width: 15%"></span>
</div>
data-variant="empty" draws nothing, so the part after it starts partway along the track
<div class="flex flex-col gap-4">
<div class="progress" role="img" aria-label="Raised the risk score 25.3 times">
<span data-variant="empty" style="width: 50%"></span>
<span data-variant="destructive" style="width: 35%"></span>
</div>
<div class="progress" role="img" aria-label="Lowered the risk score to 0.4 times">
<span data-variant="empty" style="width: 40%"></span>
<span data-variant="success" style="width: 10%"></span>
</div>
</div>
The extra large track with a list under it shows how a total divides
Cancellations by Reason
678 cancellations in the last 30 days
- Other60%
- Recurring payment declined23%
- Not satisfied with product quality9%
- Product is too expensive5%
- Changed my mind3%
<div class="card">
<header>
<h2>Cancellations by Reason</h2>
<p>678 cancellations in the last 30 days</p>
</header>
<section class="flex flex-col gap-3">
<div class="progress" data-size="xl" role="img" aria-label="Cancellations by reason: Other 60%, Recurring payment declined 23%, Not satisfied with product quality 9%, Product is too expensive 5%, Changed my mind 3%">
<span style="width: 60%"></span>
<span style="width: 23%"></span>
<span style="width: 9%"></span>
<span style="width: 5%"></span>
<span style="width: 3%"></span>
</div>
<ul class="text-sm">
<li class="flex items-center gap-2 border-t py-3"><span class="bg-chart-5 size-2.5 rounded-xs" aria-hidden="true"></span><span>Other</span><span class="ms-auto font-semibold tabular-nums">60%</span></li>
<li class="flex items-center gap-2 border-t py-3"><span class="bg-chart-4 size-2.5 rounded-xs" aria-hidden="true"></span><span>Recurring payment declined</span><span class="ms-auto font-semibold tabular-nums">23%</span></li>
<li class="flex items-center gap-2 border-t py-3"><span class="bg-chart-3 size-2.5 rounded-xs" aria-hidden="true"></span><span>Not satisfied with product quality</span><span class="ms-auto font-semibold tabular-nums">9%</span></li>
<li class="flex items-center gap-2 border-t py-3"><span class="bg-chart-2 size-2.5 rounded-xs" aria-hidden="true"></span><span>Product is too expensive</span><span class="ms-auto font-semibold tabular-nums">5%</span></li>
<li class="flex items-center gap-2 border-t py-3"><span class="bg-chart-1 size-2.5 rounded-xs" aria-hidden="true"></span><span>Changed my mind</span><span class="ms-auto font-semibold tabular-nums">3%</span></li>
</ul>
</section>
</div>
A track divided into parts takes role="img" and an aria-label that states the parts. Use five parts at most.
The page moves the bar by setting the width and aria-valuenow together
<div class="flex flex-col gap-4">
<div id="demo-progress-script" class="progress" role="progressbar" aria-label="Importing products" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
<span style="width: 10%"></span>
</div>
<button type="button" class="btn self-start" data-variant="outline" data-size="sm" id="demo-progress-script-button">Add 15%</button>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const progress = document.getElementById("demo-progress-script");
document.getElementById("demo-progress-script-button").addEventListener("click", () => {
const value = Math.min(100, Number(progress.getAttribute("aria-valuenow")) + 15);
progress.setAttribute("aria-valuenow", value);
progress.querySelector("span").style.width = value + "%";
});
});
</script>
API Reference
Attributes
| Attribute | On | Values | Default | Description |
|---|---|---|---|---|
| data-size | .progress | "sm", "lg", "xl" | none (6px) | The track's height: 4px, 12px or 32px. The 32px track has the card's corners in place of a full round. |
| data-variant | a span | "success", "warning", "info", "destructive", "empty" | none | The colour of that part. Without it a single part is primary, and several parts are five blues, the darkest first. "empty" draws nothing, so the track shows through and the part after it starts partway along. |
| style="width: n%" | a span | a percentage | none | That part's share of the track. The widths of all the spans add up to 100% or less. |
| role | .progress | "progressbar", "img" | none | "progressbar" for one value moving toward a goal; "img" for a track divided into parts. |
| aria-valuenow, aria-valuemin, aria-valuemax | .progress with role="progressbar" | numbers | none | The value and its range, for a screen reader. aria-valuenow matches the span's width. |
| aria-valuetext | .progress with role="progressbar" | text | none | The value in words, when a bare number says too little: "7.8 GB of 10 GB". |
| aria-label, or aria-labelledby | .progress | text, or an id | none | What is progressing, or for role="img" the parts stated in words. Required. |
The progress bar has no script, no methods and no events. The page sets the width and aria-valuenow.
A change of width is animated by the stylesheet.