Switch
Switch is a UI element that let users choose between two states.
SwitchRoot API
Import
import * as Switch from '@base_ui/react/Switch';
const SwitchRoot = Switch.Root;Props of the native component are also available.
| Name | Type | Default | Description | 
|---|---|---|---|
| checked | bool | - | If  | 
| className | func | string | - | Class names applied to the element or a function that returns them based on the component's state. | 
| defaultChecked | bool | - | The default checked state. Use when the component is not controlled. | 
| disabled | bool | false | If  | 
| id | string | - | The id of the switch element. | 
| inputRef | ref | - | Ref to the underlying input element. | 
| name | string | - | Name of the underlying input element. | 
| onCheckedChange | func | - | Callback fired when the checked state is changed. Signature: function(checked: boolean, event: React.ChangeEvent
 | 
| readOnly | bool | false | If  | 
| render | element | func | - | A function to customize rendering of the component. | 
| required | bool | false | If  | 
ref is forwarded to the root element.Theme default props
You can useSwitchRoot to change the default props of this component with the theme.SwitchThumb API
Import
import * as Switch from '@base_ui/react/Switch';
const SwitchThumb = Switch.Thumb;Props of the native component are also available.
| Name | Type | Description | 
|---|---|---|
| className | func | string | Class names applied to the element or a function that returns them based on the component's state. | 
| render | element | func | A function to customize rendering of the component. | 
ref is forwarded to the root element.Theme default props
You can useSwitchThumb to change the default props of this component with the theme.