Skip to content
+

Switch

Switches are UI elements that let users choose between two states—most commonly on/off.

  • Feedback
  • Bundle size
  • WAI-ARIA
Component demosComponents APIHooks API

Switch API

Import

import { Switch } from '@mui/base/Switch';
// or
import { Switch } from '@mui/base';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

checked

If true, the component is checked.

Type:bool


className

Class name applied to the root element.

Type:string


defaultChecked

The default checked state. Use when the component is not controlled.

Type:bool


disabled

If true, the component is disabled.

Type:bool


onChange

Callback fired when the state is changed.

Type:func

Signature:
function(event: React.ChangeEvent) => void
  • event The event source of the callback. You can pull out the new value by accessing event.target.value (string). You can pull out the new checked state by accessing event.target.checked (boolean).

readOnly

If true, the component is read only.

Type:bool


required

If true, the input element is required.

Type:bool


slotProps

The props used for each slot inside the Switch.

Type:{ input?: func
| object, root?: func
| object, thumb?: func
| object, track?: func
| object }

Default:{}


slots

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.

Type:{ input?: elementType, root?: elementType, thumb?: elementType, track?: elementType
| null }

Default:{}



The ref is forwarded to the root element.

Slots

To learn how to customize the slot, check out the Overriding component structure guide.

root

The component that renders the root.

Class name: .MuiSwitch-root

Default component: 'span'


input

The component that renders the input.

Class name: .MuiSwitch-input

Default component: 'input'


thumb

The component that renders the thumb.

Class name: .MuiSwitch-thumb

Default component: 'span'


track

The component that renders the track.

Class name: .MuiSwitch-track

Default component: 'span'


CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

.Mui-checkedSTATE

State class applied to the root element if the switch is checked


.Mui-disabledSTATE

State class applied to the root element if the switch is disabled


.Mui-focusVisibleSTATE

State class applied to the root element if the switch has visible focus


.Mui-readOnlySTATE

Class applied to the root element if the switch is read-only


Edit this page

Was this page helpful?


SliderToggle Button Group

Blog

Store