Component
Toggle Switch Input
Toggle switch components for boolean settings and preferences
- Component
- Tailwind
- MIT
Preview
Live component
9:41 100%
devsnips.dev/library/tailwind/components/input/toggle-switch/ fluid · no fixed width 100%
Install
Add to your project
npx devsnips add Tailwind/Components/Input/toggle-switch Tailwind/Components/Input/toggle-switch <!-- Toggle Switch - Default -->
<div class="space-y-4">
<div class="flex items-center justify-between">
<span class="text-sm font-medium text-gray-700">Enable notifications</span>
<button class="relative w-12 h-6 bg-gray-200 rounded-full transition-colors peer-checked:bg-blue-600">
<input type="checkbox" class="sr-only peer" />
<span class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow-sm transition-transform peer-checked:translate-x-6"></span>
</button>
</div>
<div class="flex items-center justify-between">
<span class="text-sm font-medium text-gray-700">Dark mode</span>
<button class="relative w-12 h-6 bg-blue-600 rounded-full transition-colors">
<input type="checkbox" checked class="sr-only" />
<span class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow-sm transition-transform translate-x-6"></span>
</button>
</div>
<div class="flex items-center justify-between">
<span class="text-sm font-medium text-gray-700">Disabled</span>
<button class="relative w-12 h-6 bg-gray-200 rounded-full opacity-50 cursor-not-allowed">
<input type="checkbox" class="sr-only" disabled />
<span class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow-sm"></span>
</button>
</div>
</div>
<!-- Toggle Switch - Pill -->
<div class="mt-6 p-4 bg-gray-50 rounded-xl">
<div class="flex items-center justify-between mb-4">
<div>
<p class="text-sm font-medium text-gray-900">Push notifications</p>
<p class="text-xs text-gray-500">Receive alerts on your device</p>
</div>
<button class="relative w-14 h-8 bg-gray-200 rounded-full transition-colors">
<input type="checkbox" class="sr-only" />
<span class="absolute top-1 left-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform translate-x-6"></span>
</button>
</div>
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-900">Email digest</p>
<p class="text-xs text-gray-500">Weekly summary to your inbox</p>
</div>
<button class="relative w-14 h-8 bg-green-500 rounded-full transition-colors">
<input type="checkbox" checked class="sr-only" />
<span class="absolute top-1 left-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform translate-x-6"></span>
</button>
</div>
</div>
<!-- Toggle Switch - Colored -->
<div class="mt-6 space-y-3">
<div class="flex items-center justify-between">
<span class="text-sm font-medium text-gray-700">Success state</span>
<button class="relative w-12 h-6 bg-green-500 rounded-full transition-colors">
<input type="checkbox" checked class="sr-only" />
<span class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow transition-transform translate-x-6"></span>
</button>
</div>
<div class="flex items-center justify-between">
<span class="text-sm font-medium text-gray-700">Warning state</span>
<button class="relative w-12 h-6 bg-amber-500 rounded-full transition-colors">
<input type="checkbox" checked class="sr-only" />
<span class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow transition-transform translate-x-6"></span>
</button>
</div>
</div> # Toggle Switch
Toggle switch control.
## Usage
```bash
npx devsnips add Tailwind/Components/Input/toggle-switch
```
Copy from `code.html`. Prefer switch semantics (`role="switch"`) when appropriate.
## File Structure
`code.html` · `preview.html` · `metadata.json` · `README.md` 66 lines UTF-8 · LF · Spaces: 2
Continue browsing