Video examples
iOS Voiceover
Windows Jaws Chrome
Windows NVDA Chrome
MacOS Voiceover Safari
Code examples
Use as much semantic HTML as possible
- This semantic HTML contains all accessibility features by default, and only requires the addition of
role="switch"
. - It uses CSS pseudo attributes to create the toggle switch indicator, no Javascript
Disabled
Using the disabled
attribute will prevent the input from switching on/off and will also prevent it from being focusable.
Screen readers will still be able to discover the switch by browsing with the arrow keys.
Disabled and focusable
There are limited scenarios when it’s helpful for screenreaders to more easily perceive a disabled toggle, use aria-disabled="true"
and prevent click events with scripting.
Using a <button>
as a switch
This <button>
toggle has focus and keyboard criteria built in. It requires the addition of role="switch"
and scripting to toggle aria-checked="true/false"
.
When you can’t use semantic HTML
This custom switch requires extra attributes and keyboard event listeners.