Custom Input Controls
You'll learn how to build accessible custom checkboxes, radio buttons, and switches that work for everyone, including keyboard and screen reader users.
Why Custom Controls Need Extra Care
When you replace native HTML controls (like <input type="checkbox">) with custom-styled <div> or <span> elements, you lose all the built-in accessibility features browsers provide. Your custom control won't respond to keyboard navigation, won't announce its state to screen readers, and won't participate in form validation without extra work.
The Foundation: ARIA Roles and States
Think of ARIA (Accessible Rich Internet Applications) attributes as instructions you give assistive technologies about what your custom element is and what it's doing.
For a custom checkbox, you need:
role="checkbox"– tells screen readers "this behaves like a checkbox"aria-checked="true"or"false"– announces the current statetabindex="0"– makes it keyboard-focusable
For radio buttons: role="radio", aria-checked, and group them with role="radiogroup".
For switches: role="switch", aria-checked="true" or "false".
Keyboard Support is Essential
Native controls respond to Space (toggle) and arrow keys (for radio groups). Your custom controls must do the same. Listen for keydown events and handle Space, Enter, and arrow key navigation just like the native versions would.
The Complete Picture
A truly accessible custom control requires: proper ARIA roles, dynamic state management (updating aria-checked when clicked), keyboard event handling, visual focus indicators, and association with labels using aria-labelledby or wrapping <label> elements.
Key Takeaway: Custom input controls require ARIA roles, keyboard support, and state management to match the accessibility of native HTML controls—beauty shouldn't come at the cost of usability.