shadcn.io is not affiliated with official shadcn/ui
Switch examples · Icons
Volume Toggle Switch for React
A switch between a muted and a volume icon, starting on.
A Switch between a muted speaker and a speaker with sound, starting on. Use it for sound effects, notification sounds or a media player's mute, where the icons say what the switch does.
Preview
Installation
FAQ
What do the two icons show?
VolumeXIcon, a muted speaker, comes before the switch with size-4 text-muted-foreground. Volume2Icon comes after it with size-4. Both have aria-hidden, and the row is flex items-center gap-2.
What do screen readers call this switch?
The icons are hidden from screen readers, so the switch has aria-label (Sound). On means sound plays.
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.
How do I add a visible label to this switch?
Put the Switch in a horizontal Field next to a FieldLabel. Clicking the label toggles the switch, and screen readers read the label with it.
Give the Switch an id and set the same value as htmlFor on the FieldLabel.
Related
- Theme Toggle with Icons SwitchA switch between a sun and a moon icon
- Icon with Label SwitchA switch with a bell icon and a
- Default SwitchA switch in its default off state, with
- Volume Control SliderA Volume slider with a speaker icon and
- Feature Card SwitchA bordered card with an icon, a label, a
- Switch in ItemAn outlined item with a title, a