How can I make a custom switch communicate its on and off state?
Quick answer
Use a switch when a setting has exactly two values: on and off. Give it a name that identifies the setting, and keep that name unchanged as it toggles; communicate the current state separately as on or off. If the choice is not genuinely binary, choose a control pattern that matches it. A checkbox or toggle button may also suit a binary setting, depending on how people should understand it. [S1]
The question, the details, the next step.
A practical checklist
Confirm the setting has exactly two values: on and off.
Choose a stable name that identifies the setting.
Communicate the current state separately from the name.
Check that the communicated state matches the actual setting.
Verify Space toggles the switch; treat Enter as optional.
Use a different control pattern if the choice is not a binary on/off setting.
A few more useful answers
Should the switch’s name change when it is turned on?
No. Keep the name identifying the setting stable, and communicate on or off separately as its state. [S1]
Is a switch the only suitable control for a binary choice?
No. A checkbox or toggle button can also represent binary input; choose the semantics that fit the design and how users should understand it. [S1]
Does the guidance guarantee that my custom switch will work with every device?
No. The guidance describes the switch pattern and its keyboard interaction, but does not establish the behavior of a particular implementation across devices or assistive technologies.
Sources
References used for this guide.
- [S1] WAI-ARIA Authoring Practices: Switch Pattern w3.org · Checked
