docs/components/switch
Sections
Components
Utilities
Forms
Hooks
Copy Markdown
A switch for toggling a binary state.
PreviewCode
Airplane mode
CLIManual
pnpmbunnpmyarn
pnpm dlx shadcn@latest add @shark/switch
import { Switch } from "@/components/ui/switch";
<Switch />
Use the checked and onCheckedChange props to control the switch state programmatically.
PreviewCode
Enable notifications
❌
Use the invalid prop on the Field or in the Switch component to mark the switch as invalid.
PreviewCode
Accept terms and conditions
Use the disabled prop to disable the switch.
PreviewCode
Marketing emails
Use FieldDescription to add a description to the switch.
PreviewCode
Share across devices
Focus is shared across devices, and turns off when you leave the app.
Use a card-style layout with the switch for a more prominent display.
PreviewCode
Enable notifications
You can enable or disable notifications at any time.
Integrate the switch into a form with proper validation and error handling.
PreviewCode
Terms and conditions
Please read the terms and conditions carefully.
I agree to the terms
SubmitReset
The switch size is controlled by the [--size-*] CSS variable.
PreviewCode
Toggle switch for on/off state. Use with a form control.
| Prop | Type | Default |
|---|---|---|
checked | boolean | - |
defaultChecked | boolean | false |
disabled | boolean | false |
invalid | boolean | false |
name | string | - |
value | `string | number` |
onCheckedChange | (details: CheckedChangeDetails) => void | - |
className | string | - |
| Attribute | Default |
|---|---|
--size | --spacing(4) |
For a complete list of props, see the Ark UI documentation.
[
Previous page
Steps ](/docs/components/steps)[
Next page
Table ](/docs/components/table)
On This Page
InstallationUsageControlledStatesInvalidExamplesDisabledWith DescriptionCard StyleForm IntegrationCustomizing SizeAPI ReferenceSwitch