Toggle Button
A button that can be toggled between two states.
Last updated
A button that can be toggled between two states.
Last updated
A toggle button is a special type of button that conveys a pressed or non-pressed state; this state may be conveyed programmatically via the aria-pressed attribute or via visible text alone.
Working examples will be added soon.
The toggle button must be a button (i.e. not a link) when using aria-pressed.
If the state is conveyed via visible text, a link can be used (resulting in a full page reload).
The toggle button must have only two states (whether conveyed via aria-pressed or text).
The toggle button that uses visible text to convey state change must not also use aria-pressed.
If button has focus, SPACEBAR and ENTER keys should toggle button.
If button has focus, TAB and SHIFT-TAB keys should move to the next or previous focusable page element respectively.
A classic example of a toggle button is an "add to watchlist" button (as seen in the screenshot above), often conveyed with a heart icon that changes between a filled and unfilled visual state.
Adding aria-pressed
attribute communicates the current state of the toggle button to assistive technology.
Remember, if a button state is conveyed via its button text, do not use aria-pressed.
The screenshot below shows a toggle button with a state that is conveyed via the button text (i.e. "Watch" and "Watching").
aria-pressed
Informs AT the current "pressed" state of a toggle button.