Switches
Toggle controls that share a native checkbox at the markup level, with a switch visual.
- The API is
class="switch". Userole="switch"for ARIA correctness. - The visual state tracks the native
checkedattribute. No JavaScript is required. - For strict ARIA correctness, keep
aria-checkedin sync. This is an enhancement, not the baseline.
<!-- Default: native state, no JS required. -->
<input class="switch" type="checkbox" role="switch" checked />
<!-- Enhancement: keep aria-checked in sync. -->
<input class="switch"
type="checkbox"
role="switch"
aria-checked="true"
checked
onchange="this.setAttribute('aria-checked', this.checked)" />