Switch
A toggle control for switching between two states.
switch-demo.tsx
import { Switch } from "@/components/ui/switch"
export function SwitchDemo() {
return <Switch />
}
Installation
npx shadcn@latest add @9ui/switch
Usage
Imports
import { Switch } from "@/components/ui/switch"
Anatomy
<Switch />
Examples
With Label
switch-with-label.tsx
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
export function SwitchWithLabel() {
return (
<Label className="flex items-center gap-2">
<Switch />
Enable notifications
</Label>
)
}
Disabled
switch-disabled.tsx
import { Switch } from "@/components/ui/switch"
export function SwitchDisabled() {
return <Switch disabled />
}