Skip to content
+

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';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

NameTypeDefaultDescription
checkedbool-

If true, the switch is checked.

classNamefunc
| string
-

Class names applied to the element or a function that returns them based on the component's state.

defaultCheckedbool-

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

disabledboolfalse

If true, the component is disabled and can't be interacted with.

inputRefref-

Ref to the underlying input element.

namestring-

Name of the underlying input element.

onChangefunc-

Callback fired when the state is changed.

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).
readOnlyboolfalse

If true, the component is read-only. Functionally, this is equivalent to being disabled, but the assistive technologies will announce this differently.

renderfunc-

A function to customize rendering of the component.

requiredboolfalse

If true, the switch must be checked for the browser validation to pass.


The ref is forwarded to the root element.

Theme default props

You can use Switch to change the default props of this component with the theme.

SwitchThumb API

Import

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

Props

Props of the native component are also available.

NameTypeDefaultDescription
classNamefunc
| string
-

Class names applied to the element or a function that returns them based on the component's state.

renderfunc-

A function to customize rendering of the component.


The ref is forwarded to the root element.

Theme default props

You can use SwitchThumb to change the default props of this component with the theme.