Switch
On this page
Overview
A switch provides a visible toggle for a setting. Authors must supply
an accessible label via accessible-label or a <label for>. The
element uses ARIA role="switch" with aria-checked for screen
readers. Users should toggle with Space or Enter keys. Avoid using
a switch when multiple selections are needed; use checkboxes instead.
Edit element properties
import '@rhds/elements/rh-switch/rh-switch.js';
rh-switch {
margin: var(--rh-space-lg);
}
<rh-switch id="switch-a" accessible-label="Switch A" message-on="Message when on" message-off="Message when off" checked=""></rh-switch>
import { Switch } from "@rhds/elements/react/rh-switch/rh-switch.js";
// NOTE: React 19+ does not require these wrapper imports.
// You can use the custom elements directly as-is.
export const Demo = () => (
<Switch id="switch-a" accessible-label="Switch A" message-on="Message when on" message-off="Message when off" checked />
);
invisible, accessible label for screen readers
Message to display when the switch is on (i.e. checked)
Message to display when the switch is off (i.e. unchecked)
If the checkmark icon should be displayed when the switch is on
Whether the switch is on (checked)
If the switch is disabled
If the switch is reversed: message first, then control
Status
- Figma library:
-
Ready - RH Elements:
-
Ready - RH Shared Libs:
-
Planned
When to use
- When users need to choose between two binary actions
- When users need to immediately activate or deactivate something
- When users need to toggle an item on or off
Status checklist
| Property | Status | Meaning |
|---|---|---|
| Figma library |
|
Component is available in the Figma library |
| RH Elements |
|
Component is available in RH Elements |
| RH Shared Libs |
|
Component will be added to RH Shared Libs |
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.