0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-04 16:24:22 +01:00
Bootstrap/site/content/docs/5.3/components/progress.md
Louis-Maxime Piton 7bffd6ea8d
Docs: Progress fix + proposal (#38014)
* Fix + proposal

* fix(review)

---------

Co-authored-by: Patrick H. Lauke <redux@splintered.co.uk>
2023-02-13 18:38:21 -08:00

10 KiB

layout title description group toc
docs Progress Documentation and examples for using Bootstrap custom progress bars featuring support for stacked bars, animated backgrounds, and text labels. components true

{{< callout info >}} New markup in v5.3.0 — We've deprecated the previous HTML structure for progress bars and replaced it with a more accessible one. The previous structure will continue to work until v6. [See what's changed in our migration guide.]({{< docsref "/migration#improved-markup-for-progress-bars" >}}) {{< /callout >}}

How it works

Progress components are built with two HTML elements, some CSS to set the width, and a few attributes. We don't use the HTML5 <progress> element, ensuring you can stack progress bars, animate them, and place text labels over them.

  • We use the .progress as a wrapper to indicate the max value of the progress bar.
  • The .progress wrapper also requires a role="progressbar" and aria attributes to make it accessible, including an accessible name (using aria-label, aria-labelledby, or similar).
  • We use the inner .progress-bar purely for the visual bar and label.
  • The .progress-bar requires an inline style, utility class, or custom CSS to set its width.
  • We provide a special .progress-stacked class to create multiple/stacked progress bars.

Put that all together, and you have the following examples.

{{< example >}}

{{< /example >}}

Bar sizing

Width

Bootstrap provides a handful of [utilities for setting width]({{< docsref "/utilities/sizing" >}}). Depending on your needs, these may help with quickly configuring the width of the .progress-bar.

{{< example >}}

{{< /example >}}

Height

You only set a height value on the .progress container, so if you change that value, the inner .progress-bar will automatically resize accordingly.

{{< example >}}

{{< /example >}}

Labels

Add labels to your progress bars by placing text within the .progress-bar.

{{< example >}}

25%
{{< /example >}}

Note that by default, the content inside the .progress-bar is controlled with overflow: hidden, so it doesn't bleed out of the bar. If your progress bar is shorter than its label, the content will be capped and may become unreadable. To change this behavior, you can use .overflow-visible from the [overflow utilities]({{< docsref "/utilities/overflow" >}}), but make sure to also define an explicit [text color]({{< docsref "/utilities/colors#colors" >}}) so the text remains readable. Be aware though that currently this approach does not take into account [color modes]({{< docsref "/customize/color-modes" >}}).

{{< example >}}

Long label text for the progress bar, set to a dark color
{{< /example >}}

Backgrounds

Use background utility classes to change the appearance of individual progress bars.

{{< example >}}

{{< /example >}}

{{< callout info >}} {{< partial "callouts/warning-color-assistive-technologies.md" >}} {{< /callout >}}

If you're adding labels to progress bars with a custom background color, make sure to also set an appropriate [text color]({{< docsref "/utilities/colors#colors" >}}), so the labels remain readable and have sufficient contrast.

{{< example >}}

25%
50%
75%
100%
{{< /example >}}

Alternatively, you can use the new combined [color and background]({{< docsref "/helpers/color-background" >}}) helper classes.

{{< example >}}

75%
{{< /example >}}

Multiple bars

You can include multiple progress components inside a container with .progress-stacked to create a single stacked progress bar. Note that in this case, the styling to set the visual width of the progress bar must be applied to the .progress elements, rather than the .progress-bars.

{{< example >}}

{{< /example >}}

Striped

Add .progress-bar-striped to any .progress-bar to apply a stripe via CSS gradient over the progress bar's background color.

{{< example >}}

{{< /example >}}

Animated stripes

The striped gradient can also be animated. Add .progress-bar-animated to .progress-bar to animate the stripes right to left via CSS3 animations.

{{< example >}}

{{< /example >}}

CSS

Variables

{{< added-in "5.2.0" >}}

As part of Bootstrap's evolving CSS variables approach, progress bars now use local CSS variables on .progress for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.

{{< scss-docs name="progress-css-vars" file="scss/_progress.scss" >}}

Sass variables

{{< scss-docs name="progress-variables" file="scss/_variables.scss" >}}

Keyframes

Used for creating the CSS animations for .progress-bar-animated. Included in scss/_progress-bar.scss.

{{< scss-docs name="progress-keyframes" file="scss/_progress.scss" >}}