Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Switch for React and Tailwind

A switch for toggling a binary state.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/switch.json

Anatomy

Switch
├── SwitchLabel
├── SwitchControl
└── SwitchThumb

Usage

import { Field, FieldLabel } from "@/components/ui/field";
import { Switch } from "@/components/ui/switch";
<div className="max-w-sm">
  <Field orientation="horizontal">
    <Switch defaultChecked />
    <FieldLabel> Airplane mode</FieldLabel>
  </Field>
</div>

Accessibility

KeyDescription
Space
Activate the focused control.

Demos

Card

Controlled

Description

Disabled

Form

Invalid

Size

API Reference

Switch

label

PropType
AttributeType
CSS variableType

SwitchControl

span

PropType
AttributeType
CSS variableType

SwitchThumb

span

PropType
AttributeType
CSS variableType

useSwitch