Simple Two-State Checkbox Example
Example of a simple two-state checkbox that implements the design pattern for checkbox.
Example
Label 1
Label 2
Label 3Accessibility Features
divelement withrole="checkbox".divelement hasonclickevent to handle mouse clicks.divelement hasonkeydownevent to handle keyboard support.divelement hastabindex="0"to become part of tab order of the page.imgelements are used to visually indicate the state because using css techniqes or generated content result in visual state disappearing when browsers or operating systems are configured to display high contrast themes.toggleCheckbox(event)usesaria-checkedstate to make sure the ARIA and visual state (e.g.imgelement) of the checkbox stay synchronizd.focusblurevents are used to provide visual styling of keyboard focus.
Keyboard Support
| Key | Function |
|---|---|
| Tab | Moves keyboard focus to checkbox. |
| Space | Toggle the checkbox option either true or false. False is the default. |
ARIA Roles, Properties, and States
| Role | Property/State | Usage |
|---|---|---|
| checkbox | Identify div as Checkbox widget. | |
| aria-checked |
Indicate state of checkbox:
|
Javascript and CSS Source Code
- CSS: checkbox.css
- Javascript: checkbox.js