Switch

3 Switch variations from the W3C ARIA Authoring Practices Guide.

Switch

An on/off switch built from a custom span. Its name remains stable.

Corresponding W3C APG example

Example

Switch

Keyboard interaction

Space toggles the switch. Custom and button versions also accept Enter.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-switch-change — Dispatched when the switch toggles on or off. (target: [role="switch"], detail: { checked: boolean })
  • input / change — Standard input and change events. (target: [role="switch"], detail: Native Event)

Events reference and examples

Example HTML

<axxy-scope>
  <span role="switch" aria-checked="false">Switch</span>
</axxy-scope>

Switch (Button)

An on/off switch built from a native button. Its name remains stable.

Corresponding W3C APG example

Example

Keyboard interaction

Space toggles the switch. Custom and button versions also accept Enter.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-switch-change — Dispatched when the switch toggles on or off. (target: [role="switch"], detail: { checked: boolean })
  • input / change — Standard input and change events. (target: [role="switch"], detail: Native Event)

Events reference and examples

Example HTML

<axxy-scope>
  <button type="button" role="switch" aria-checked="false">Switch</button>
</axxy-scope>

Switch (Checkbox)

An on/off switch built from a native checkbox input. Its name remains stable.

Corresponding W3C APG example

Example

Keyboard interaction

Space toggles the switch. Custom and button versions also accept Enter.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-switch-change — Dispatched when the switch toggles on or off. (target: [role="switch"], detail: { checked: boolean })
  • input / change — Standard input and change events. (target: [role="switch"], detail: Native Event)

Events reference and examples

Example HTML

<axxy-scope>
  <label>
    <input type="checkbox" role="switch">
    Switch
  </label>
</axxy-scope>