Shadcn Switch
React switch for toggle settings and preferences with smooth animations. Built with TypeScript and Tailwind CSS for Next.js using Radix UI.
Switch component broken?
Join our Discord community for help from other developers.
You know those toggle switches that just feel right when you flip them? Like the ones on your phone for airplane mode or dark theme? Ever notice how much better they feel than checkboxes for instant settings? That's what this shadcn/ui switch gives you—a satisfying binary control that users actually want to interact with in your React applications.
Switch showcase
Clean toggle for instant settings:
Just a clean toggle with clear labeling. This free open source React component handles all the accessibility requirements so screen readers know what's being toggled and users can navigate with keyboards. Built with TypeScript for full type safety while styled with Tailwind CSS to match your design system.
npx shadcn@latest add switch
Why switches beat checkboxes for instant settings
Here's the thing—checkboxes work great in forms, but switches communicate something different. When users flip a switch, they expect immediate results. Dark mode turns on. Notifications stop. Features activate. No submit button needed.
Think about your phone's settings screen. Airplane mode? Switch. Wi-Fi? Switch. Do Not Disturb? Switch. There's a reason Apple and Google use switches for system preferences—they signal instant application of the setting. Your JavaScript applications deserve the same clarity.
This free shadcn switch handles the UX psychology—that satisfying slide animation, the clear on/off state, the larger touch target. Whether you're building preference panels, feature flags, or permission toggles in your Next.js applications, switches make binary choices feel intentional and immediate.
Common switch patterns you'll actually use
Dark mode toggle
The most common switch pattern in modern apps:
Form validation with switches
Email preferences with proper validation:
Settings panel organization
App preferences grouped logically:
Feature flags and permissions
Control feature access and user capabilities:
Master switch with dependencies
Parent toggles controlling child switches:
These patterns show switches handling everything from theme preferences to complex permission systems. Each example demonstrates how this open source component adapts to different contexts while maintaining consistent interaction patterns.
Features
This free open source switch component includes everything you need:
- TypeScript-first - Full type safety with controlled and uncontrolled modes in React
- Radix UI powered - Built on battle-tested primitives with ARIA compliance
- Keyboard ready - Space and Enter keys toggle, Tab navigates naturally
- Tailwind CSS styled - Customize with utilities, not fighting CSS specificity
- Form compatible - Hidden input for proper form submission in JavaScript
- State attributes - data-state and data-disabled for advanced styling
- Mobile optimized - Large touch targets that feel natural on any device
- Animation smooth - That satisfying slide that makes switches feel premium
API Reference
Component Props
Prop | Type | Default |
---|---|---|
checked? | boolean | undefined |
onCheckedChange? | (checked: boolean) => void | undefined |
disabled? | boolean | false |
name? | string | undefined |
Keyboard Shortcuts
Key | Action |
---|---|
Space | Toggle the switch state |
Enter | Toggle the switch state |
Tab | Navigate between switches |
Switch vs Checkbox Quick Guide
Use Switch | Use Checkbox |
---|---|
Instant settings (dark mode, notifications) | Form data that needs submission |
System preferences that apply immediately | Multiple selections from a list |
Feature flags and permissions | Terms acceptance and agreements |
Binary on/off states | Data collection fields |
Production tips
Label switches clearly so users know exactly what they control. This free shadcn/ui switch component provides the interaction—you provide clear labels that explain what happens when toggled. "Enable notifications" beats "Notifications" because it tells users the action.
Group related switches visually to reduce cognitive load. When building settings panels in your Next.js applications, organize switches into logical sections. Privacy settings together, notification preferences together, appearance options together. This TypeScript component handles the individual toggles—you create the information architecture.
Show immediate feedback when switches change application state. If dark mode doesn't apply instantly, users think it's broken. This open source shadcn switch triggers onChange immediately—make sure your JavaScript code responds just as quickly with visible changes.
Consider adding confirmation dialogs for high-impact switches. Deleting all data? Disabling security features? Some switches deserve a second thought. The Tailwind CSS styled component handles the toggle—you decide when additional confirmation protects users from mistakes.
Persist switch states across sessions for better user experience. Nobody wants to re-enable dark mode every visit. This React component manages the UI state—use localStorage or your backend to remember user preferences between sessions.
Integration with other components
Switches naturally pair with Form components for preference panels and settings screens in your React applications. Use Label components for clear switch descriptions and Card components to group related switches visually.
For complex settings, combine switches with Accordion components to organize preferences into collapsible sections. This open source pattern keeps interfaces clean while providing granular control.
When building permission systems, use switches alongside Dialog components for confirmation or Alert components for warnings about security implications. Separator components help divide switch groups visually.
For comparison interfaces, pair switches with Tabs components to show different configuration sets or RadioGroup components when users need to choose one option from many. Your JavaScript application can compose these shadcn components while maintaining consistent interaction patterns.