Skip to main content

Switch

A control that allows the user to toggle between checked and not checked.

import { Switch } from "@/components/ui/switch"

<div className="flex items-center gap-3">
<Switch id="airplane-mode" />
<label htmlFor="airplane-mode">Airplane mode</label>
</div>

Disabled

The switch can be disabled to prevent interaction.

<div className="flex items-center gap-3">
<Switch id="disabled-switch" disabled />
<label htmlFor="disabled-switch">Disabled</label>
</div>

API Reference

PropTypeDefaultDescription
checkedbooleanThe controlled checked state of the switch
defaultCheckedbooleanfalseThe checked state when initially rendered
onCheckedChange(checked: boolean) => voidCallback when the checked state changes
disabledbooleanfalseWhen true, prevents the user from interacting with the switch
requiredbooleanfalseWhen true, indicates the switch must be checked for form submission
namestringThe name of the switch used when submitting a form
valuestring"on"The value given as data when submitted with a name

Accessibility

The Switch component follows WAI-ARIA switch patterns:

  • Uses role="switch" with proper aria-checked state
  • Supports keyboard interaction (Space to toggle)
  • Can be associated with a label via htmlFor / id pairing
  • Focus ring is visible for keyboard navigation