Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Switch for React

A switch for toggling a binary state.

Installation

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

Anatomy

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

Usage

import { Field, FieldLabel } from "@/components/ui/field";
import { Switch } from "@/components/ui/switch";
<Field className="w-fit" orientation="horizontal">
  <Switch />
  <FieldLabel>Airplane Mode</FieldLabel>
</Field>

Accessibility

KeyDescription
Space
Activate the focused control.

Demos

Description

Switch with a label and description.

Choice Card

Card-style selection where FieldLabel wraps the entire Field for a clickable card pattern.

Disabled

Add the disabled prop to the Switch and Field to disable the control.

Invalid

Add aria-invalid to the Switch and invalid to the Field for invalid styling.

Sizes

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

Rtl

Right-to-left switch. See the RTL configuration guide for document direction.

API Reference

Switch

span

PropType
AttributeType

SwitchThumb

span

AttributeType