Make your AI a shadcn expert

Shadcn Switch

React switch for dark mode, notifications, and feature flags. Built with TypeScript and Tailwind CSS for Next.js using Base UI — checked or unchecked, sm or default.

A switch is instant on or off. Flip it and the setting applies now — dark mode, notifications, a feature flag. If the choice should wait for submit, that is a Checkbox.

Scroll to load preview...

Looking for a neobrutalism version for shadcn?

Same switch, thicker borders. The NeoBrutalism switch is the kit if you want that look.

Usage

import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
<div className="flex items-center gap-2">
  <Switch id="airplane-mode" />
  <Label htmlFor="airplane-mode">Offline mode</Label>
</div>

defaultChecked for uncontrolled. checked plus onCheckedChange when you own the state.

Composition

Switch

The thumb is inside the root. Pair it with Field for the label.

Description

FieldContent plus FieldDescription for the helper line under the label.

Scroll to load preview...

Choice Card

FieldLabel wraps the whole Field so the card is the click target.

Scroll to load preview...

Disabled

disabled on the switch, data-disabled on the Field so the label greys out with it.

Scroll to load preview...

Invalid

aria-invalid on the switch. data-invalid on the Field. Both, or the label stays the wrong color.

Scroll to load preview...

Size

size="sm" in a dense list. Default is default.

Scroll to load preview...

RTL

Wrap with DirectionProvider and dir="rtl". Labels stay Arabic.

Scroll to load preview...

API

Prop

Type

Keyboard

KeyAction
SpaceToggle the focused switch
EnterToggle the focused switch
TabMove to the next control

Notes

Invalid needs two attributes

aria-invalid on the switch, data-invalid on the Field. One without the other leaves the control or the label unstyled.

If the setting should wait for submit, that is a Checkbox.

With other components

Questions

Was this page helpful?

Sign in to leave feedback.