Skip to content

Commit a51aaee

Browse files
julien-deramondmdo
andauthored
Docs: improve progress bar labels markup and explanations for accessibility (#39364)
* Docs: improve progress bar labels markup and explanations for accessibility * Update site/content/docs/5.3/components/progress.md --------- Co-authored-by: Mark Otto <[email protected]>
1 parent 5c75fda commit a51aaee

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

site/content/docs/5.3/components/progress.md

+13-19
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ Add labels to your progress bars by placing text within the `.progress-bar`.
7575
</div>
7676
{{< /example >}}
7777

78-
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" >}}).
78+
### Long labels
7979

80-
{{< example >}}
81-
<div class="progress" role="progressbar" aria-label="Example with label" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
82-
<div class="progress-bar overflow-visible text-dark" style="width: 10%">Long label text for the progress bar, set to a dark color</div>
83-
</div>
84-
{{< /example >}}
80+
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" >}}).
81+
82+
{{< callout warning >}}
83+
Labels longer than the progress bar within may not be fully accessible using this method because it relies on the text color having the correct contrast ratio with both the `.progress` and `.progress-bar` background colors. Use caution when implementing this example.
84+
85+
If the text can overlap the progress bar, we often recommend displaying the label outside of the progress bar for better accessibility.
86+
{{< /callout >}}
8587

8688
## Backgrounds
8789

@@ -106,28 +108,20 @@ Use background utility classes to change the appearance of individual progress b
106108
{{< partial "callouts/warning-color-assistive-technologies.md" >}}
107109
{{< /callout >}}
108110

109-
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.
111+
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. We recommend using the [color and background]({{< docsref "/helpers/color-background" >}}) helper classes.
110112

111113
{{< example >}}
112114
<div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
113-
<div class="progress-bar bg-success" style="width: 25%">25%</div>
115+
<div class="progress-bar text-bg-success" style="width: 25%">25%</div>
114116
</div>
115117
<div class="progress" role="progressbar" aria-label="Info example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
116-
<div class="progress-bar bg-info text-dark" style="width: 50%">50%</div>
118+
<div class="progress-bar text-bg-info" style="width: 50%">50%</div>
117119
</div>
118120
<div class="progress" role="progressbar" aria-label="Warning example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
119-
<div class="progress-bar bg-warning text-dark" style="width: 75%">75%</div>
121+
<div class="progress-bar text-bg-warning" style="width: 75%">75%</div>
120122
</div>
121123
<div class="progress" role="progressbar" aria-label="Danger example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
122-
<div class="progress-bar bg-danger" style="width: 100%">100%</div>
123-
</div>
124-
{{< /example >}}
125-
126-
Alternatively, you can use the new combined [color and background]({{< docsref "/helpers/color-background" >}}) helper classes.
127-
128-
{{< example >}}
129-
<div class="progress" role="progressbar" aria-label="Warning example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
130-
<div class="progress-bar text-bg-warning" style="width: 75%">75%</div>
124+
<div class="progress-bar text-bg-danger" style="width: 100%">100%</div>
131125
</div>
132126
{{< /example >}}
133127

0 commit comments

Comments
 (0)