Toggle
Toggles (also known as switches) allow users to turn a single option on or off. Built on top of Radix UI primitives for accessibility.
Basic Usage
import { Toggle } from '@/components'
<Toggle id="notifications" />
<label htmlFor="notifications">Enable notifications</label>States
Toggles support two states: off (unchecked) and on (checked).
Unchecked (Off)
Checked (On)
Off (Unchecked)
<Toggle />On (Checked)
<Toggle checked />Disabled
Disabled toggles cannot be interacted with and display a muted appearance.
Disabled states
Off
On
<Toggle disabled />
<Toggle disabled checked />Controlled
You can control the toggle state externally using the checked and onCheckedChange props.
const [checked, setChecked] = useState(false)
<Toggle
checked={checked}
onCheckedChange={setChecked}
/>With Labels
Toggles work great in settings forms with descriptive labels.
Receive emails about new products and features.
Get notified about security updates.
<div className="flex items-center justify-between">
<div>
<label htmlFor="marketing">Marketing emails</label>
<p>Receive emails about new products.</p>
</div>
<Toggle id="marketing" />
</div>All States Overview
Off
On
Default
Disabled
Accessibility
- Built on Radix UI Switch primitive for robust accessibility
- Full keyboard support (Space to toggle)
- Proper ARIA attributes for screen readers
- Supports
aria-labelandaria-labelledbyfor labeling - Focus states are clearly visible
API Reference
Toggle Props
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | false | The controlled checked state |
| defaultChecked | boolean | - | The default checked state (uncontrolled) |
| onCheckedChange | (checked: boolean) => void | - | Callback when checked state changes |
| disabled | boolean | false | Whether the toggle is disabled |
| required | boolean | false | Whether the toggle is required |
| name | string | - | Name for form submission |
| value | string | "on" | Value for form submission |
| className | string | - | Additional CSS classes |