Switch
Switches are UI elements that let users choose between two states—most commonly on/off.
Switch API
Import
import { Switch } from '@mui/base/Switch';
// or
import { Switch } from '@mui/base';Props of the native component are also available.
| Name | Type | Default | Description | 
|---|---|---|---|
| checked | bool | - | If  | 
| className | string | - | Class name applied to the root element. | 
| defaultChecked | bool | - | The default checked state. Use when the component is not controlled. | 
| disabled | bool | - | If  | 
| onChange | func | - | Callback fired when the state is changed. Signature: function(event: React.ChangeEvent
 | 
| readOnly | bool | - | If  | 
| required | bool | - | If  | 
| slotProps | { input?: func | object, root?: func | object, thumb?: func | object, track?: func | object } | {} | The props used for each slot inside the Switch. | 
| slots | { input?: elementType, root?: elementType, thumb?: elementType, track?: elementType | null } | {} | The components used for each slot inside the Switch. Either a string to use a HTML element or a component. See Slots API below for more details. | 
ref is forwarded to the root element.To learn how to customize the slot, check out the Overriding component structure guide.
| Slot name | Class name | Default component | Description | 
|---|---|---|---|
| root | .base-Switch-root | 'span' | The component that renders the root. | 
| input | .base-Switch-input | 'input' | The component that renders the input. | 
| thumb | .base-Switch-thumb | 'span' | The component that renders the thumb. | 
| track | .base-Switch-track | 'span' | The component that renders the track. | 
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
| Class name | Description | 
|---|---|
| .base--checked | State class applied to the root element if the switch is checked | 
| .base--disabled | State class applied to the root element if the switch is disabled | 
| .base--focusVisible | State class applied to the root element if the switch has visible focus | 
| .base--readOnly | Class applied to the root element if the switch is read-only |