shadcn.io is not affiliated with official shadcn/ui
Switch examples · Icons
Icon with Label Switch for React
A switch with a bell icon and a Notifications label, starting on.
A settings row with a bell icon, a label and a Switch that starts on. The icon helps people scan a long list of settings; the label names the setting and toggles the switch when clicked.
Preview
Installation
FAQ
How are the bell, the label and the switch arranged?
The row is flex items-center gap-3, and BellIcon is size-4 text-muted-foreground with aria-hidden. The label and the switch sit in a horizontal Field, where the label grows and pushes the switch to the end.
Why does Notifications toggle the switch?
The FieldLabel and the Switch share a Field.
The Switch has an id, and the FieldLabel points at it with htmlFor.
How do I control this switch in React?
The switch starts on through its default prop, which only sets the starting state; after that it keeps its own state. To control it, keep the on or off state in your own state and pass it back.
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.
Related
- Theme Toggle with Icons SwitchA switch between a sun and a moon icon
- Volume Toggle SwitchA switch between a muted and a volume
- Default SwitchA switch in its default off state, with
- Feature Card SwitchA bordered card with an icon, a label, a
- Switch in ItemAn outlined item with a title, a
- Settings Card SwitchA bordered settings card with a bell, a