Skip to content

Commit ae735c3

Browse files
Docs: give unlabelled checkbox, radio and switch examples an aria-label="..." and explain how to fill it (#43079)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ebd627c commit ae735c3

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎site/src/content/docs/content/images.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ And with a reverse alignment:
5252

5353
If you are using the `<picture>` element to specify multiple `<source>` elements for a specific `<img>`, make sure to add the `.img-*` classes to the `<img>` and not to the `<picture>` tag.
5454

55+
Give the `<img>` an `alt` text that describes the image, or an empty `alt=""` when it’s only decorative. The `alt="..."` in the example below is a placeholder for that text.
56+
5557
```html
5658
<picture>
5759
<source srcset="..." type="image/svg+xml">

‎site/src/content/docs/forms/checkbox.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ All checkbox styling is applied with the `.check` class directly on the `<input>
1717

1818
For folks looking to replace our provided icons, override the `--bs-check-icon-checked` and `--bs-check-icon-indeterminate` CSS variables (or the `--check-icon-*` Sass tokens) with your own `mask-image` URLs.
1919

20-
Labels and layout are handled with additional HTML and CSS.
20+
Labels and layout are handled with additional HTML and CSS. A checkbox without a visible label still needs an accessible name for assistive technologies, for instance with `aria-label`. The name should say what the checkbox does, like `aria-label="Select all rows"`, and replaces the `...` placeholder in the examples below. See the [forms overview accessibility]([[docsref:/forms/overview/#accessibility]]) section for details.
2121

22-
<Example code={`<input type="checkbox" id="check" class="check" checked />`} />
22+
<Example code={`<input type="checkbox" id="check" class="check" checked aria-label="..." />`} />
2323

2424
## Indeterminate
2525

2626
Checkboxes can utilize the indeterminate pseudo class when manually set via JavaScript. There is no available HTML attribute for specifying it.
2727

28-
<Example addStackblitzJs class="bd-example-indeterminate" code={`<input type="checkbox" id="checkIndeterminate" class="check" />`} />
28+
<Example addStackblitzJs class="bd-example-indeterminate" code={`<input type="checkbox" id="checkIndeterminate" class="check" aria-label="..." />`} />
2929

3030
## With form field
3131

‎site/src/content/docs/forms/radio.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { getData } from '@libs/data'
1212

1313
Similar to checkboxes, radios are styled with the `.radio` class. However, there’s no custom SVG as we use pure CSS to style the input and its checked state.
1414

15-
<Example code={`<input type="radio" id="radio" class="radio" />`} />
15+
A radio without a visible label still needs an accessible name for assistive technologies, for instance with `aria-label`. The name should say what the option is, like `aria-label="Red"` in a color picker, and replaces the `...` placeholder in the example below. See the [forms overview accessibility]([[docsref:/forms/overview/#accessibility]]) section for details.
16+
17+
<Example code={`<input type="radio" id="radio" class="radio" aria-label="..." />`} />
1618

1719
## With form field
1820

‎site/src/content/docs/forms/switch.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import { getData } from '@libs/data'
1111

1212
Switches work by layering an invisible checkbox over the custom switch indicator. This preserves interactivity while giving you a completely customizable layer underneath. Switches also include the `switch` attribute for browsers that support it, which provides haptic feedback when toggling.
1313

14+
A switch without a visible label still needs an accessible name for assistive technologies, for instance with `aria-label`. The name should say what the switch turns on or off, like `aria-label="Email notifications"`, and replaces the `...` placeholder in the example below. See the [forms overview accessibility]([[docsref:/forms/overview/#accessibility]]) section for details.
15+
1416
<Example code={`<div class="switch">
15-
<input type="checkbox" value="" id="switch" role="switch" switch>
17+
<input type="checkbox" value="" id="switch" role="switch" switch aria-label="...">
1618
</div>`} />
1719

1820
## With form field

0 commit comments

Comments
 (0)