The document discusses the challenges of styling custom radio buttons and checkboxes to ensure accessibility across different browsers and devices. It outlines a solution that uses semantic elements with key accessibility features, such as associating input and label elements, providing off-screen label content for screen readers, and ensuring keyboard-friendliness. Additionally, it provides code examples and styling techniques to enhance the visual appearance of these controls without compromising accessibility.
The main issueis that these elements are notoriously hard to style - especially across multiple browsers and devices.
6.
In the past,some developers resorted to JavaScript-based solutions to solve this problem.
7.
In some casesthis involved using JS to remove the original radio or checkbox element making the end result inaccessible for a wide range of assistive technologies.
The solution I’mabout to demo, has four key accessibility features:
13.
Feature 1: Using theintended semantic elements, the input and label elements will be explicitly associated using matching "for" and "id" values.
14.
Feature 2: The labelcontent can used to describe the purpose of each switch for screen readers. This content is hidden off-screen.
15.
Feature 3: The tickicon makes the two different states clearly distinguishable - aiding colour- blind users and some types of cognitive-impaired users.
16.
Feature 4: The switchis keyboard-friendly (operates in the normal way) but we also clearly flag the focus and hover states.
The control isthen positioned on top of the parent, and set with opacity: 0. This means it exists on the page, and can be interacted with, but it cannot be seen.
And finally, thelabel content is hidden off screen so that it is available for screen readers, but does not clutter the visual appearance of the switch.