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

Usage

import { Switch } from "@/components/ui/switch";
<Switch />

Controlled

Use the checked and onCheckedChange props to control the switch state programmatically.

States

Invalid

Use the invalid prop on the Field or in the Switch component to mark the switch as invalid.

Examples

Disabled

Use the disabled prop to disable the switch.

With Description

Use FieldDescription to add a description to the switch.

Card Style

Use a card-style layout with the switch for a more prominent display.

Form Integration

Integrate the switch into a form with proper validation and error handling.

Customizing Size

The switch size is controlled by the [--size-*] CSS variable.

API Reference

Switch

Toggle switch for on/off state. Use with a form control.

PropTypeDefault
checkedboolean-
defaultCheckedbooleanfalse
disabledbooleanfalse
invalidbooleanfalse
namestring-
valuestring | number"on"
onCheckedChange(details: CheckedChangeDetails) => void-
classNamestring-
AttributeDefault
--size--spacing(4)

For a complete list of props, see the Ark UI documentation.