Home Components Switch
React Switch Components
20 free React switches built with Tailwind CSS and shadcn/ui conventions. Copy the code or install with the shadcn CLI. Great for settings toggles and on/off states.
Switch 1 : Basic toggle switch with a clickable Enable Notifications label beside it.Switch 2 : Square-cornered switch with a square thumb instead of the usual pill shape.Switch 3 : Four solid colour switches in red, teal, blue and amber for destructive, success, info and warning.Switch 4 : Gradient switch whose track goes from yellow when off to blue and indigo when on.Switch 5 : Outline switches in red, teal, blue and yellow with a tinted track and coloured thumb when on.Switch 6 : Mini switch with a thin three pixel track and an oversized bordered thumb.Switch 7 : Three switches side by side in small, medium and large sizes.Switch 8 : Switch with check and X icons beside it that highlight to match the current state.Switch 9 : Wide switch with check and X icons inside the track and a thumb that slides over them.Switch 10 : Rounded-square theme switch with moon and sun icons inside and a half-width sliding thumb.Switch 11 : Bordered settings card for Auto Sync with a description and a sync icon that rotates when on.Switch 12 : Preference list of three switches for privacy, notifications and dark theme, each with an icon.Switch 13 : Email updates settings card that gets a primary border and glow ring when switched on.Switch 14 : Cloud backup card on a grey background that gains a dark ring and raised shadow when on.Switch 15 : Switch whose label text changes between Notifications On and Notifications Off.Switch 16 : Light and dark mode switch with clickable sun and moon icons on either side.Switch 17 : Switch with a single label icon that swaps between a moon and a sun as it toggles.Switch 18 : Yes or No switch with clickable text labels on both sides that dim when inactive.Switch 19 : Auto sync row on a muted panel with helper text that changes with the switch state.Switch 20 : Pill-shaped alerts toggle with a bell icon that swaps to a muted bell and text when paused.
About React Switch Components A React switch is an on and off toggle for a setting that takes effect right away, like dark mode or notifications. Watermelon UI switches are built on the Radix UI Switch primitive with Tailwind CSS, so they use role="switch", toggle with Space, and can be controlled or uncontrolled. Add one with the shadcn CLI, then pair it with a Label and wire checked and onCheckedChange.
When to use it Notification and privacy settings that save immediately. Feature toggles in an admin panel. Theme or billing period toggles, like monthly versus yearly. When to use something else Use Checkbox when the choice is only applied when a form is submitted. Use Radio Group when there are more than two options. Use Button when the control runs a one-off action instead of holding a state. Frequently asked questions How do I use a shadcn switch as a dark mode toggle? Read resolvedTheme and setTheme from useTheme in next-themes, pass checked={resolvedTheme === "dark"}, and call setTheme(checked ? "dark" : "light") in onCheckedChange. Render it after mount, since the theme is unknown on the server.
How do I control a shadcn switch? Pass checked from state and update it in onCheckedChange. Use defaultChecked instead if you do not need to read the value in React.
How do I add a label to a switch? Give the Switch an id and point a Label at it with htmlFor. Clicking the label then toggles the switch and screen readers read the label.
How do I change the switch size or color? Pass size="sm" for the smaller built-in size, or className with checked-state classes such as data-checked:bg-emerald-500 for a custom color. Going larger than default means editing the track and thumb sizes in your switch file so they still line up.
How to use React Switch Components Start from a React project with Tailwind CSS and shadcn/ui set up. Next.js, Vite, Remix, and Astro all work. Run npx shadcn@latest add https://registry.watermelon.sh/r/switch-1.json to add the source files to your project. Import it where you need it, then edit the Tailwind classes and design tokens to match your product. Dependencies installed with it: react-icons.
The code is yours: it lives in your repository, so there is no runtime package to keep updated. Watermelon UI is free and open source under the MIT license.
More: Free React components , UI library alternatives , guides .