Switch Examples
19 on and off toggles: settings rows, theme and sound switches, feature flags, with labels, descriptions, icons, square shapes and card layouts. Each on React, Vue, Svelte and Solid, with Base UI, React Aria, Ark UI or Radix UI on React.
Every switch example
19 examples.
- Checked SwitchStandardA switch with no visible label that starts on. Its accessible name is Wi-Fi, and the demo shows no other control.

- Default SwitchStandardA switch with no visible label, starting off. Its accessible name is Airplane mode, and nothing else is on screen.

- Disabled SwitchStandardA switch named Bluetooth that starts off, faded to half opacity, and left out of the tab order.

- Feature CardCardsA bordered card with a plus icon, the label Enable Feature, a short placeholder description, and a switch that starts off.

- Icon with LabelIconsA bell icon, the label Notifications, and a switch that starts on. Clicking the label toggles the switch.

- Settings CardCardsA bordered card with a bell emoji, the label Notifications, a short description, and a switch that starts off.

- Settings ListCardsTwo divided rows: Marketing emails starts off, and Security emails starts on, each with a label and a description.

- Small SwitchStandardA smaller switch with no visible label, starting off. Its accessible name is Compact mode.

- Square SwitchSquareA switch with square corners on the track and the thumb, starting off, and named Enable feature.

- Square Switch with LabelSquareA square switch that starts on, beside the label Enable notifications. Clicking that label toggles the switch.

- Square Switch with TextSquareA wide square switch that starts on, with On on the track in capitals. Off shows when it is turned off.

- Square Theme ToggleSquareA moon icon, a square switch that starts off, and a sun icon. The icons do not swap, and the page theme does not change.

Or describe it. With Pro, your AI agent installs the switch example you describe, on your framework and UI library.
Get ProGalleries
More component examples
8 related galleries, free: open one for its live examples and their code.
Pricing
Switch examples MCP, with Pro
Your AI agent installs any of the 1364 examples, and every component, block and icon, with every Pro plan.
4.9/5 out of 5 · 150+ reviewsfrom 150+ founders and developers.
- Secure checkout via Stripe
- Code lives in your repo
- Keep what you've shipped if you cancel
- License terms
FAQ
Frequently asked questions
A Switch is a two-state control for a setting that takes effect at once, such as airplane mode, dark mode or notifications. The thumb slides along the track to show on or off. These examples use shadcn.io's Switch, available on Base UI, React Aria, Ark UI and Radix UI for React, and on Ark UI for Vue, Svelte and Solid. Screen readers announce it as a switch, on or off.
Yes. Every switch example is free to use in personal and commercial projects. Seeing the code and installing an example takes a free shadcn.io account.
Use a Switch for a setting that applies at once and can be flipped back, such as dark mode. Use a Checkbox for a choice submitted later with a form, or for picking several items in a list. Use a Toggle for a pressed or unpressed button in a toolbar, such as bold or italic.
Usually, yes: people expect a switch to act as soon as it moves, so a separate Save button works against it. For a setting that needs confirmation, such as one that costs money, ask in an Alert Dialog first, or use a Checkbox in a form with a Save button.
Keep a pending flag. While the request runs, disable the switch and show a small Spinner beside it. On success, keep the new state; on error, set the switch back and show a message next to it. Disabling it during the request stops a second toggle from racing the first.
For settings rows, the label and an optional description go first and the switch goes at the end, as in the Switch with Description and Settings List examples. Put the Switch and a FieldLabel in a Field so that clicking the label toggles the switch and screen readers read it as the switch's name.
Place icons beside it, as the theme and volume examples do: a sun and a moon, or a muted and a sounding speaker. Mark the icons aria-hidden and give the switch an aria-label, since the icons alone are not a name.
Sign in, open an example and run the install command under its code. It adds the example to your project, with the Switch and any other components it uses if they aren't in your ui folder yet.
Give the Switch a name: when on, it submits its value, which defaults to on, and when off it submits nothing. With a form library, bind its boolean value to the switch's checked state. The Form guides show this for each framework.
Use the size prop for the built-in sizes, default and sm. For other sizes or colors, edit the Switch file in your ui folder, where the track and thumb are plain Tailwind classes; the on and off styles use the data-checked and data-unchecked variants (data-selected with React Aria).
shadcn.io's Switch (on Base UI, React Aria, Ark UI or Radix UI for React, and on Ark UI for Vue, Svelte and Solid), Tailwind CSS, and Lucide icons in the examples with icons. The switch keeps its own state unless you control it, so no state library is needed.
Yes. The Switch is announced as a switch with its on or off state. Tab moves focus to it, and Space or Enter toggles it. Examples without a visible label give the switch an aria-label, and labeled ones use a FieldLabel that toggles the switch when clicked.
The Switch is a client component, since it keeps state and handles input; render it from a Server Component like any client component. To save a setting on the server, call a Server Action from the switch's change handler.
4.9 out of 5 from 150+ developers
Every switch example. One prompt away.
Every switch example is free with an account. With Pro, your AI agent installs them from a prompt.
Get Pro


















