Show the completion of a task with progress bars that take labels, context colors, stacked segments, and animated stripes.
Introduction
Progress bars show how much of a task or process is complete. The component is built from two <div> elements instead of the HTML <progress> element, which makes room for labels inside the bar, stacked segments, and striped or animated backgrounds.
Key features
The component is made of these parts:
- Wrapper (
.progress) — the track, which carries theprogressbarrole and the ARIA values. - Bar (
.progress-bar) — the filled part, whose width shows the progress. - Stack (
.progress-stacked) — a track that holds several segments. - Modifiers (
.striped,.animated) — a striped background on the bar, and its animation.
Basic structure
Wrap a .progress-bar in a .progress element. The wrapper carries role="progressbar", a label, and the aria-valuenow, aria-valuemin, and aria-valuemax attributes; the width of the bar shows the value and is set separately, here with an inline style.
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: 0%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: 25%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: 50%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: 75%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: 100%"></div>
</div>Width
Set the width of the bar with an inline style, a sizing utility, or custom CSS. Keep it in step with aria-valuenow.
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar w-75"></div>
</div>Height
Set a height on the .progress wrapper to change the height of the track. The .progress-bar inside stretches to fill it.
<div class="progress" role="progressbar" aria-label="Example 1px high" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="height: 1px">
<div class="progress-bar" style="width: 25%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Example 20px high" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="height: 20px">
<div class="progress-bar" style="width: 25%"></div>
</div>Labels
Place text inside the .progress-bar element to label it. The label is centered in the bar by default and takes the foreground color of the bar.
<div class="progress" role="progressbar" aria-label="Example with label" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar text-end" style="width: 25%"><span class="mx-2xs">25%</span></div>
</div>Long labels
The .progress-bar element has overflow: hidden, which cuts off a label that is wider than the bar. An overflow utility such as .overflow-visible lets the label extend past the bar.
A label that extends past the bar sits partly on the .progress background and partly on the .progress-bar color, and may not have enough contrast with both. When the length of a label varies, place it outside the progress bar.
Colors
The bar uses the primary color by default. Apply a background utility to the .progress-bar to give it the color of another context.
<div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-success" style="width: 25%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Info example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-info" style="width: 50%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Warning example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-warning" style="width: 75%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Danger example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-danger" style="width: 100%"></div>
</div>Accessibility tip: Color alone shouldn't convey meaning as it's not perceived by assistive technology users. Ensure clarity through text with adequate contrast, ARIA attributes where needed, and consider using .visually-hidden for screen reader content.
Label contrast
A label on a bar with a background utility needs a matching foreground color. Add the .fg-contrast class of the contrast helper so the label stays readable on the background.
<div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar fg-contrast bg-success" style="width: 25%">25%</div>
</div>
<div class="progress" role="progressbar" aria-label="Info example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar fg-contrast bg-info" style="width: 50%">50%</div>
</div>
<div class="progress" role="progressbar" aria-label="Warning example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar fg-contrast bg-warning" style="width: 75%">75%</div>
</div>
<div class="progress" role="progressbar" aria-label="Danger example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar fg-contrast bg-danger" style="width: 100%">100%</div>
</div>Stacked bars
Place several .progress elements in a .progress-stacked container to show segments in one track. In a stack the width goes on each .progress element, whose bar fills it, and each segment keeps its own role, label, and ARIA values.
<div class="progress-stacked">
<div class="progress" role="progressbar" aria-label="Segment one" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" style="width: 15%">
<div class="progress-bar"></div>
</div>
<div class="progress" role="progressbar" aria-label="Segment two" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="width: 30%">
<div class="progress-bar bg-success"></div>
</div>
<div class="progress" role="progressbar" aria-label="Segment three" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">
<div class="progress-bar bg-info"></div>
</div>
</div>Striped bars
Add .striped to a .progress-bar to lay a striped gradient over its background color.
<div class="progress" role="progressbar" aria-label="Default striped example" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar striped" style="width: 10%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Success striped example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar striped bg-success" style="width: 25%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Info striped example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar striped bg-info" style="width: 50%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Warning striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar striped bg-warning" style="width: 75%"></div>
</div>
<div class="progress" role="progressbar" aria-label="Danger striped example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar striped bg-danger" style="width: 100%"></div>
</div>Animated stripes
Add .animated to a striped bar to move the stripes along the bar with a CSS animation.
<div class="progress" role="progressbar" aria-label="Animated striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar striped animated" style="width: 75%"></div>
</div>Chassis CSS respects user accessibility preferences by automatically disabling animations when the prefers-reduced-motion media query is detected. See the reduced motion guidelines in the accessibility documentation for implementation details.
Accessibility
A progress bar built from <div> elements has no native semantics, so the markup has to supply them:
- Add
role="progressbar"to the.progresswrapper, not to the bar. - Label the wrapper with
aria-labeloraria-labelledby. - Set
aria-valuenowto the current value, andaria-valueminandaria-valuemaxto the range. Updatearia-valuenowtogether with the width of the bar. - Check the contrast of a label against the bar, and of the bar against the track, when a background utility or a custom color is used.
CSS
This component can be customized through Sass variables at compile time.
Custom properties
This component exposes CSS custom properties to control its appearance at runtime.
--height: var(--progress-height, #{$progress-height});
@include clamp($progress-font-size, --font-size);
@include clamp($progress-line-height, --line-height);
--bg-color: var(--progress-bg-color, #{$progress-bg-color});
--border-radius: var(--progress-border-radius, #{$progress-border-radius});
--box-shadow: var(--progress-box-shadow, #{$progress-box-shadow});
--bar-fg-color: var(--progress-bar-fg-color, #{$progress-bar-fg-color});
--bar-bg-color: var(--progress-bar-bg-color, #{$progress-bar-bg-color});
--bar-box-shadow: var(--progress-bar-box-shadow, #{$progress-bar-box-shadow});
--bar-transition: var(--progress-bar-transition, #{$progress-bar-transition});
--bar-animation-timing: var(--progress-bar-animation-timing, #{$progress-bar-animation-timing});Sass variables
This component uses Sass variables in scss/config/_defaults.scss to define its defaults.
$progress-height: 1rem;
$progress-font-size: calc(#{$font-size-base} * .75);
$progress-line-height: calc(#{$line-height-base} * .75);
$progress-bg-color: var(--bg-even);
$progress-border-radius: var(--border-radius-md);
$progress-box-shadow: none; // var(--box-shadow-inset);
$progress-bar-fg-color: var(--primary-contrast-color);
$progress-bar-bg-color: var(--primary-base-color);
$progress-bar-box-shadow: none; // $box-shadow-emboss; //
$progress-bar-animation-timing: 1s linear infinite;
$progress-bar-transition: width .6s ease;Keyframes
The progress-bar-stripes keyframes move the striped background by the height of the bar. The .animated modifier uses them, and they are emitted only when $enable-transitions is on.
@if $enable-transitions {
@keyframes progress-bar-stripes {
0% { background-position-x: $progress-height; }
}
}