Switch
Keyboard navigation
Users should have the ability to move focus to a Switch and toggle it on or off using their keyboard.
Key | Result |
---|---|
Tab | Move focus to the Switch |
Space | Toggles the Switch on and off |
Focus order
A logical focus order helps keyboard users operate our websites. Elements need to receive focus in an order that preserves meaning, therefore the focus order should make sense and not jump around randomly. If Switches are stacked, focus lands on each as it moves from top to bottom. Each Switch should have the ability to be toggled.
Touch targets
Grouped Switches are adequately spaced for optimal touch targets.
Using form labels
Like other form elements, switches require labels that are available to assistive tech. These labels may be visible or visually hidden. A label captions its associated switch, offering an indication of its purpose (e.g., “Dark mode”). It’s important to note that a label is not the same as a status message (e.g., “On” and “Off”), and though it's associated with the switch and can control it, the label is not part of the Switch web component.
Visible labels
If you’re using a visible label, associate it with your switch:
- Ensure your
<rh-switch>
element has an id value. - Add a
<label>
element before<rh-switch>
with afor
attribute pointing to the switch’sid
.
Visually-hidden labels
If your label will not be visible, caption your switch via the accessible-label
attribute.
Screen reader guidelines
A Switch should communicate the following to users.
- If a Switch is on or off
- What the status messages say
- What happens when a Switch is toggled
ARIA Authoring Practices Guide (APG)
Learn to use the accessibility semantics defined by the Accessible Rich Internet Application (ARIA) specification to create accessible web experiences.
Web Content Accessibility Guidelines
Understanding documents provide detailed explanations for Web Content Accessibility Guidelines (WCAG) guidelines and success criteria.
- SC 2.1.1 Keyboard (Level A)
- SC 2.1.3 Keyboard (No exception) (Level AAA)
- SC 2.4.3 Focus order (Level A)
- SC 2.5.5 Target size (Level AAA)
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.