How you design and implement your toggle buttons is quite up to you, but I hope you’ll remember this post when it comes to adding this particular component to your pattern library. There’s no reason why toggle buttons — or any interface component for that matter — should marginalize the number of people they often do.
You can take the basics explored here and add all sorts of design nuances, including animation. It’s just important to lay a solid foundation first.
Checklist
- Use form elements such as checkboxes for on/off toggles if you are certain the user won’t believe they are for submitting data.
- Use
<button>
elements, not links, witharia-pressed
orrole="switch"
plusaria-checked
.- Don’t change label and state together.
- When using visual “on” and “off” text labels (or similar) you can override these with a unique label via
aria-labelledby
.- Be careful to make sure the contrast level between the button’s text and background color meets WCAG 2.0 requirements.
See the source link for very detailed descriptions of all of these points.