An on/off toggle you can tap, press or drag, with a thumb that stretches under your finger and an optional pending state for saves.
Install
Add it to your project
Run this in a project set up for shadcn/ui. It writes the files and installs the npm packages.
First time: connect the Infinity UI registry
- Create a personal token on your Tokens page.
- Put it in
.env.localasINFINITYUI_TOKEN. - Add the registry to
components.json:
{
"registries": {
"@infinityui": {
"url": "https://infinityui.io/r/{name}.json",
"headers": {
"Authorization": "Bearer ${INFINITYUI_TOKEN}"
}
}
}
}Using Claude Code, Codex, Cursor, Lovable or v0? See CLI & MCP for a setup prompt.
npm packages it adds
- cn
- @base-ui/react
- @tabler/icons-react
- class-variance-authority
Code
import { Switch } from "@/components/ui/switch"
const settings = [
{
id: "wifi",
title: "Wi-Fi",
description: "Join known networks automatically.",
on: true,
},
{
id: "bluetooth",
title: "Bluetooth",
description: "Connect to headphones and keyboards.",
on: false,
},
{
id: "airdrop",
title: "Nearby sharing",
description: "Let people around you send files.",
on: true,
},
]
export function SwitchDemo() {
return (
<div className="flex w-full max-w-sm flex-col divide-y rounded-xl border">
{settings.map((setting) => (
<label
key={setting.id}
className="flex items-center justify-between gap-4 p-4 text-sm"
>
<span className="flex flex-col gap-0.5">
<span className="font-medium">{setting.title}</span>
<span className="text-muted-foreground">{setting.description}</span>
</span>
<Switch defaultChecked={setting.on} />
</label>
))}
</div>
)
}
































