Search documentation

Search components and pages

Switch

A control that toggles between checked and not checked.

01

Installation

Add the switch component with the shadcn CLI.

bash
npx shadcn@latest add https://swiss.ui.unsanity.ai/r/switch.json
02

Usage

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

Examples

Default

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

<div className="flex items-center gap-2">
  <Switch id="airplane" defaultChecked />
  <Label htmlFor="airplane">Airplane mode</Label>
</div>