Installation
- CLI
- Manual
Usage
Import the toggle component:API Reference
Toggle
Props ExtendsReact.ComponentProps<typeof ToggleRoot> from Base UI.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "outline" | "default" | The visual style variant |
size | "default" | "sm" | "lg" | "default" | The size of the toggle |
defaultPressed | boolean | false | The initial pressed state (uncontrolled) |
pressed | boolean | - | The controlled pressed state |
onPressedChange | (pressed: boolean) => void | - | Callback when pressed state changes |
disabled | boolean | false | Whether the toggle is disabled |
TypeScript
Examples
Default
The default toggle with transparent background:Outline
Toggle with a border and subtle shadow:With Text
Combine icons with text labels:Sizes
The toggle component comes in three sizes:Disabled
Disable user interaction:Controlled
Control the toggle state with React state:Variants
Default
Transparent background with hover and pressed states:Outline
Bordered variant with background on hover:Accessibility
- Uses the
buttonrole witharia-pressedattribute - Supports keyboard navigation (Space and Enter keys)
- Clearly indicates pressed state to screen readers
- Always include an
aria-labelfor icon-only toggles
