Switch

Accessible React switch for a single binary setting that applies immediately, with label, helper text, and states. Built on Radix and mirrored in RTL.

Switch flips one boolean that takes effect right away. For a choice confirmed on submit, use Checkbox instead.

When to use

Use Switch for a setting that takes effect the moment it changes: notifications on or off, dark mode, or showing archived items. If the choice is saved when a form is submitted, use Checkbox, because a switch implies an immediate result.

Label the setting, not the states. "Email alerts" is clearer than "On/Off".

Examples

Setting toggle

On by default, with a hint

States

Arabic label

Props

Props declared by Switch. Native attributes of the underlying element pass through.

PropTypeDefaultDescription
labelreact.ReactNodeVisible label, sits beside the track, associated via htmlFor/id.
helperTextreact.ReactNodeHint shown below the row. Hidden while an error message is showing.
errorMessagereact.ReactNodeMessage shown below the row when error is true.
errorbooleanMarks the field invalid: sets aria-invalid and error styling.
asChildboolean
checkedboolean
defaultCheckedboolean
requiredboolean
onCheckedChange(checked: boolean) => void

Accessibility

Switch exposes role="switch" with aria-checked, so screen readers announce it as a switch and read its state. Space toggles it, and the label is associated so clicking it works.

The thumb moves along the reading direction, so the on position sits at the inline end in RTL. The thumb position carries the state as well as the color.