Switch accessibility
WCAG 2.1 AA requirements
Semantics
- Renders a
<button>withrole="switch"andaria-checkeddriven by thecheckedprop. - Screen readers announce the state as "on" or "off".
type="button"prevents accidental form submission.
Keyboard interaction
| Key | Action |
|---|---|
Tab | Move focus to the switch. |
Space | Toggle the on/off state. |
Standard <button> behaviour — no custom key handling needed.
Label pairing
- Always pair with a
Labellinked viaid/htmlFor. The label becomes a click target and provides the accessible name. - If a visible label is not possible, set
aria-labelon the Switch directly.
Focus ring
- A 2px focus ring (
ring-ring) appears onfocus-visiblewithring-offset-2. - Never remove the focus ring without a replacement.
Disabled state
disabledsets the native disabled attribute on the<button>, which impliesaria-disabled.- Visual treatment: 50% opacity and
cursor-not-allowed.
Reduced motion
- The thumb slide transition uses
duration-short(200ms). The user agent suppresses the animation whenprefers-reduced-motionis active.
Audit checklist
-
role="switch"andaria-checkedpresent - Tab-able and Space toggles
- Visible focus ring on keyboard navigation
- Paired with a
LabelviahtmlFor - Disabled state is both visual and semantic
- Thumb animation respects reduced motion