Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Switch examples · Cards

Feature Card Switch for React

A bordered card with an icon, a label, a description and a switch.

Framework
UI library

A feature toggle in a card: a plus icon on a primary tile, the feature's name and a short description, and a Switch. Use it for add-ons, beta features or modules people turn on one at a time.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How is the plus icon drawn?

PlusIcon is size-5 inside a size-10 shrink-0 rounded-lg tile with bg-primary text-primary-foreground, so it follows your theme. The card is flex items-start gap-3 rounded-lg border bg-background p-4.

How is Enable Feature tied to the switch?

A horizontal Field holds a FieldContent, with the FieldLabel and the FieldDescription, and then the Switch. The Switch has an id, and the FieldLabel points at it with htmlFor.

How do I control this switch in React?

Nothing in this file sets the on state, so the switch starts off and keeps its own state. To control it, keep the on or off state in your own state and pass it back. To start it on, use the default prop. The prop is defaultChecked. Pass checked; onCheckedChange receives the new boolean.

Does this switch submit with a form?

Give it a name. When on, it submits its value, which defaults to on. When off, it submits nothing. With Base UI, uncheckedValue sets what it submits when off.

How do I make this switch smaller?

Set size="sm". The default size is default. For a different track or thumb, edit those classes in the Switch file in your ui folder.

Which keys toggle the switch?

Tab moves focus to the switch. Space toggles it, and so does Enter.