Switch

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

Installation

npx shadcn@latest add @fulldev/switch

Usage

---
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
---
<Label>
  <Switch name="notifications" />
  Notifications
</Label>

Label a switch by wrapping it in Label. Switch renders a span, which Label for cannot point to.

Examples

With Label

Card-style selection where FieldLabel wraps the switch and its text, so the whole card is the click target.

Disabled

Add the disabled prop to the Switch component to disable the switch, and dim its text for styling.

Sizes

Use the size prop to change the size of the switch.

API Reference

See the GitHub source code for more information on props. See the data-slot docs for more information on interactivity.