Switch
Material 3 switch guidance with immediate on/off semantics, optional thumb content, focus treatment, and form behavior.
Switches represent an immediate on/off setting. Activating the control changes the setting directly; use a checkbox instead when the user is selecting options to submit or confirm later.
import { Switch } from '@m3-ui/ui';
<Switch defaultSelected>Notifications</Switch>When to use
Use a switch for settings whose result takes effect as soon as the state changes, such as enabling automatic updates. Use checkboxes for independent form choices and toggle buttons for persistent button-like modes/actions.
Selection state
Switch inherits controlled and uncontrolled React Aria selection props. Application state is the source of truth; do not style the track or thumb directly to simulate selection.
<Switch isSelected={enabled} onChange={setEnabled}>
Automatic updates
</Switch>Thumb content
thumbContent renders decorative/supporting content inside the Material thumb while the switch remains the only semantic control.
<Switch thumbContent={<CheckIcon />} defaultSelected>
Enabled
</Switch>Do not place a second interactive control inside the thumb.
Behavior and states
React Aria supplies switch semantics, keyboard/pointer behavior, disabled state, form participation, and controlled/uncontrolled selection. Material tokens own track/thumb geometry, color, ripple/state layers, and minimum interaction size.
The global ThemeProvider ripple-focus configuration can change the visual focus treatment without changing the underlying switch semantics.
Accessibility
Visible children should identify the setting. A control-only switch needs an explicit accessible name. Keep the label stable as state changes; the switch role communicates on/off state.
Do not rely only on thumb color or icon to communicate state. Disabled switches should be used only when the setting is genuinely unavailable.
API reference
Switch
Switch({ children, thumbContent, className, style, onPressEnd, onPressStart, ...props }: SwitchProps): JSX.ElementProps
| Name | Type | Default | Description | Origin |
|---|---|---|---|---|
thumbContent | ReactNode | — | Content rendered inside the Material thumb. Compose expects a 16dp icon-sized child. | @m3-ui/ui |
Inherited React / web props (105)
| Name | Type | Default | Description | Origin |
|---|---|---|---|---|
aria-controls | string | undefined | — | Identifies the element (or elements) whose contents or presence are controlled by the current element. | react-aria |
aria-describedby | string | undefined | — | Identifies the element (or elements) that describes the object. | @react-types/shared |
aria-details | string | undefined | — | Identifies the element (or elements) that provide a detailed, extended description for the object. | @react-types/shared |
aria-errormessage | string | undefined | — | Identifies the element that provides an error message for the object. | @react-types/shared |
aria-label | string | undefined | — | Defines a string value that labels the current element. | @react-types/shared |
aria-labelledby | string | undefined | — | Identifies the element (or elements) that labels the current element. | @react-types/shared |
autoFocus | boolean | undefined | — | Whether the element should receive focus on render. | @react-types/shared |
children | ChildrenOrFunction<SwitchRenderProps> | — | The children of the component. A function may be provided to alter the children based on component state. | react-aria-components |
className | ClassNameOrFunction<SwitchRenderProps> | undefined | 'react-aria-Switch' | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. | react-aria-components |
defaultSelected | boolean | undefined | — | Whether the element should be selected (uncontrolled). | react-stately |
dir | string | undefined | — | — | @react-types/shared |
excludeFromTabOrder | boolean | undefined | — | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. | @react-types/shared |
form | string | undefined | — | The `<form>` element to associate the input with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). | @react-types/shared |
hidden | boolean | undefined | — | — | @react-types/shared |
id | string | undefined | — | The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). | @react-types/shared |
inert | boolean | undefined | — | — | @react-types/shared |
inputRef | React.Ref<HTMLInputElement | null> | undefined | — | A ref for the HTML input element. | react-aria-components |
isDisabled | boolean | undefined | — | Whether the input is disabled. | @react-types/shared |
isReadOnly | boolean | undefined | — | Whether the input can be selected but not changed by the user. | @react-types/shared |
isSelected | boolean | undefined | — | Whether the element should be selected (controlled). | react-stately |
lang | string | undefined | — | — | @react-types/shared |
name | string | undefined | — | The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). | @react-types/shared |
onAnimationEnd | AnimationEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onAnimationEndCapture | AnimationEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onAnimationIteration | AnimationEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onAnimationIterationCapture | AnimationEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onAnimationStart | AnimationEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onAnimationStartCapture | AnimationEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onAuxClick | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onAuxClickCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onBlur | ((e: FocusEvent<Element, Element>) => void) | undefined | — | Handler that is called when the element loses focus. | @react-types/shared |
onChange | ((isSelected: boolean) => void) | undefined | — | Handler that is called when the element's selection state changes. | react-stately |
onClick | ((e: MouseEvent<FocusableElement>) => void) | undefined | — | **Not recommended – use `onPress` instead.** `onClick` is an alias for `onPress` provided for compatibility with other libraries. `onPress` provides additional event details for non-mouse interactions. | @react-types/shared |
onClickCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onContextMenu | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onContextMenuCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onDoubleClick | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onDoubleClickCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onFocus | ((e: FocusEvent<Element, Element>) => void) | undefined | — | Handler that is called when the element receives focus. | @react-types/shared |
onFocusChange | ((isFocused: boolean) => void) | undefined | — | Handler that is called when the element's focus status changes. | @react-types/shared |
onGotPointerCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onGotPointerCaptureCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onHoverChange | ((isHovering: boolean) => void) | undefined | — | Handler that is called when the hover state changes. | @react-types/shared |
onHoverEnd | ((e: HoverEvent) => void) | undefined | — | Handler that is called when a hover interaction ends. | @react-types/shared |
onHoverStart | ((e: HoverEvent) => void) | undefined | — | Handler that is called when a hover interaction starts. | @react-types/shared |
onKeyDown | ((e: KeyboardEvent) => void) | undefined | — | Handler that is called when a key is pressed. | @react-types/shared |
onKeyUp | ((e: KeyboardEvent) => void) | undefined | — | Handler that is called when a key is released. | @react-types/shared |
onLostPointerCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onLostPointerCaptureCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseDown | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseDownCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseEnter | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseLeave | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseMove | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseMoveCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseOut | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseOutCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseOver | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseOverCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseUp | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onMouseUpCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerCancel | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerCancelCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerDown | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerDownCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerEnter | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerLeave | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerMove | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerMoveCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerOut | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerOutCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerOver | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerOverCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerUp | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPointerUpCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onPress | ((e: PressEvent) => void) | undefined | — | Handler that is called when the press is released over the target. | @react-types/shared |
onPressChange | ((isPressed: boolean) => void) | undefined | — | Handler that is called when the press state changes. | @react-types/shared |
onPressEnd | ((e: PressEvent) => void) | undefined | — | Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. | @react-types/shared |
onPressStart | ((e: PressEvent) => void) | undefined | — | Handler that is called when a press interaction starts. | @react-types/shared |
onPressUp | ((e: PressEvent) => void) | undefined | — | Handler that is called when a press is released over the target, regardless of whether it started on the target or not. | @react-types/shared |
onScroll | UIEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onScrollCapture | UIEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchCancel | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchCancelCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchEnd | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchEndCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchMove | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchMoveCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchStart | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTouchStartCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionCancel | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionCancelCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionEnd | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionEndCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionRun | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionRunCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionStart | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onTransitionStartCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onWheel | WheelEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
onWheelCapture | WheelEventHandler<HTMLLabelElement> | undefined | — | — | @react-types/shared |
render | DOMRenderFunction<"label", SwitchRenderProps> | undefined | — | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements: - You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`). - Only a single root DOM element can be rendered (no fragments). - You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate. | react-aria-components |
slot | string | null | undefined | — | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. | react-aria-components |
style | StyleOrFunction<SwitchRenderProps> | undefined | — | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. | react-aria-components |
translate | "yes" | "no" | undefined | — | — | @react-types/shared |
value | string | undefined | — | The value of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue). | react-stately |
Source: packages/ui/src/components/Switch/Switch.tsx:31
Material fidelity and web adaptation
- Family
- Switches
- Provenance
- spec: Material 3 overview · web: Browser and React Aria semantics · adaptation: m3-ui web adaptation
- Compose mapping
- Switch
- Visual fidelity
- partial: Legacy visual fidelity has not received an explicit reviewed disposition. Current implementation evidence: Implements Material selected and unselected track/thumb states, optional thumb content, disabled treatment, hover and focus state layers, and both supported ripple focus treatments.
- Behavior fidelity
- adapted: React Aria owns switch semantics, selection state, keyboard and pointer interaction, focus visibility, and labeling. Optional thumb content maps Compose icon-sized thumb content into React content without changing the control semantics.
- Semantics fidelity
- adapted: React Aria owns switch semantics, selection state, keyboard and pointer interaction, focus visibility, and labeling. Optional thumb content maps Compose icon-sized thumb content into React content without changing the control semantics.
- Adaptations
- React Aria owns switch semantics, selection state, keyboard and pointer interaction, focus visibility, and labeling. Optional thumb content maps Compose icon-sized thumb content into React content without changing the control semantics.
Material provides the on/off visual contract and state treatment. React Aria supplies the browser switch role, accessible selected state, keyboard behavior, and form semantics.
Related components
- Checkbox — independent choices.
- Toggle button — button-like persistent selection.
- Forms and validation — native form composition.