shadcn.io is not affiliated with official shadcn/ui
The plain Switch: a track and a thumb, off until someone turns it on. Start here for any on or off setting that takes effect at once, then add a label, a description or a card around it as the other examples do.
Preview
Installation
FAQ
What does this switch render?
One Switch with only an aria-label. It starts off and keeps its own state, so nothing else in the file runs.
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.
What do screen readers call this switch?
It has no visible label, so the demo passes aria-label (Airplane mode). Change it to the setting the switch controls, or use a visible FieldLabel instead.
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.
Related
- Checked SwitchA switch that starts on and keeps its own
- Small SwitchA small switch for dense layouts such as
- Disabled SwitchA disabled switch that shows its state
- Square SwitchA switch with square corners on its track
- Settings Card SwitchA bordered settings card with a bell, a
- Simple CheckboxA checkbox with a label for a single