ARIA Widget Roles

ARIA role: switch

A binary on/off control, without an indeterminate state. Requires aria-checked and an accessible name. Space toggles; Enter is optional for custom switches. Keep the label stable as state changes. Explicit roles do not implement visual presentation, interaction or focus management; verify allowed role/element combinations in ARIA in HTML. Accessibility exposure varies with browser, platform and assistive technology. Test relevant combinations; rendering is not proof of accessibility.

Formal Syntax & Structure

html syntaxhtml
role="switch"

Parameters & Attributes

NameTypeDescription
roletokenExplicit role token switch; use only where allowed. Omit when native semantics match.
aria-checkedtristateRequired for this custom role unless equivalent host semantics apply. Reports whether a checkable widget is checked, unchecked, or partially checked. Mixed applies only to roles supporting tri-state behavior; not radio or switch. Keep this in sync with the real state. Native checkbox checked and indeterminate properties are preferable where applicable. Values: true, false, mixed, undefined.

Working Example

Example Snippethtml
<style>  [role=switch][aria-checked=true]{font-weight:bold;border:3px solid currentColor}</style><button type="button" role="switch" aria-checked="false" onclick="this.setAttribute('aria-checked',String(this.getAttribute('aria-checked')!=='true'))">Dark mode</button>
HTML Reference