Switch

OverviewStyleGuidelinesCodeAccessibilityDemos

Keyboard navigation

Users should have the ability to move focus to a Switch and toggle it on or off using their keyboard.

Diagram of switch with text and arrows that show what can be controlled by keyboard
Key Result
Tab Move focus to the Switch
Space Toggles the Switch on and off

Focus order

A logical focus order helps keyboard users operate our websites. Elements need to receive focus in an order that preserves meaning, therefore the focus order should make sense and not jump around randomly. If Switches are stacked, focus lands on each as it moves from top to bottom. Each Switch should have the ability to be toggled.

Diagram with four switches and numbers 1 to 4 indicating focus order

Touch targets

Grouped Switches are adequately spaced for optimal touch targets.

group of four switches and red circles with low opacity over each switch

Using form labels

Like other form elements, switches require labels that are available to assistive tech. These labels may be visible or visually hidden. A label captions its associated switch, offering an indication of its purpose (e.g., “Dark mode”). It’s important to note that a label is not the same as a status message (e.g., “On” and “Off”), and though it's associated with the switch and can control it, the label is not part of the Switch web component.

Visible labels

If you’re using a visible label, associate it with your switch:

  1. Ensure your <rh-switch> element has an id value.
  2. Add a <label> element before <rh-switch> with a for attribute pointing to the switch’s id.

Visually-hidden labels

If your label will not be visible, caption your switch via the accessible-label attribute.

Screen reader guidelines

A Switch should communicate the following to users.

  • If a Switch is on or off
  • What the status messages say
  • What happens when a Switch is toggled

ARIA Authoring Practices Guide (APG)

Learn to use the accessibility semantics defined by the Accessible Rich Internet Application (ARIA) specification to create accessible web experiences.

View APG resources

Web Content Accessibility Guidelines

Understanding documents provide detailed explanations for Web Content Accessibility Guidelines (WCAG) guidelines and success criteria.