Skip to content

QuizNot attempted

A custom toggle switch

You build a toggle switch from a <button> styled as a pill. What makes it accessible?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • role="switch" with aria-checked kept in sync, plus a visible or aria-label name
  • role="switch" announces an on/off control, aria-checked must reflect the current state, and it needs a name
  • building it on a real <button> gives focus and Enter/Space for free.
  • Not aria-pressed on a div without tabindex: can't be reached by keyboard.
  • Not colour alone: invisible to screen readers and fails users with colour-vision deficiencies.
  • Not role=checkbox on a span with click: not focusable and no keyboard activation.