Read This First
No ARIA is better than Bad ARIA. Before using any ARIA, read this to understand why.
How to build accessibility semantics into web patterns and widgets
No ARIA is better than Bad ARIA. Before using any ARIA, read this to understand why.
A switch is an input widget that allows users to choose one of two values: on
or off
.
Switches are similar to checkboxes and toggle buttons, which can also serve as binary inputs.
One difference, however, is that switches can only be used for binary input while checkboxes and toggle buttons allow implementations the option of supporting a third middle state.
Checkboxes can be checked
or not checked
and can optionally also allow for a partially checked
state.
Toggle buttons can be pressed
or not pressed
and can optionally allow for a partially pressed
state.
Since switch, checkbox, and toggle button all offer binary input, they are often functionally interchangeable.
Choose the role that best matches both the visual design and semantics of the user interface.
For instance, there are some circumstances where the semantics of on or off
would be easier for assistive technology users to understand than the semantics of checked or unchecked
, and vice versa.
Consider a widget for turning lights on or off.
In this case, screen reader output of Lights switch on
is more user friendly than Lights checkbox checked
.
However, if the same input were in a group of inputs labeled Which of the following must be included in your pre-takeoff procedures?
, Lights checkbox checked
would make more sense.
Important: it is critical the label on a switch does not change when its state changes.
div
element that turns a notification preference on and off.button
elements that turn lights on and off.input[type="checkbox"]
elements that turn accessibility preferences on and off.switch
.switch
.switch
.on
, the switch element has state aria-checked set to true
.off
, the switch element has state aria-checked set to false
.input[type="checkbox"]
, it uses the HTML checked
attribute instead of the aria-checked
property.fieldset
and the label for the set is contained in an HTML legend
element.This is an unpublished draft preview that might include content that is not yet approved. The published website is at w3.org/WAI/.