Switch
The <Switch>
component allows the users to select between two states, e.g. on and off.
It consists of a visual selection indicator and a label.
Users may click or touch a Switch to toggle the state, or use the tab key to navigate to it and the space key to toggle it.
Anatomy

The styles are separated into some parts (container, label, thumb, track) that you can style in a custom variant.
Appearance
The appearance of a component can be customized using the variant
and size
props. These props adjust the visual style and dimensions of the component, available values are based on the active theme.
Property | Type | Description |
---|---|---|
variant | - | The available variants of this component. |
size | - | The available sizes of this component. |
Usage
Switches are best used to adjust settings and other standalone options. They make a binary selection, like on and off or true and false.
The effects of a switch should start immediately, without needing to save.

Immediately activate or deactivate something.

Avoid using a switch to select multiple options that require people to save. Switches should be immediate.

Avoid using switches to toggle between opposing options.
Props
aria-controls?
string;
aria-describedby?
string;
aria-details?
string;
aria-label?
string;
aria-labelledby?
string;
autoFocus?
boolean;
defaultSelected?
boolean;
dir?
string;
disabled?
boolean;
"false"
excludeFromTabOrder?
boolean;
form?
string;
<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.hidden?
boolean;
id?
string;
inert?
boolean;
inputRef?
RefObject<HTMLInputElement | null>;
label?
ReactNode;
lang?
string;
name?
string;
onAnimationEnd?
AnimationEventHandler<HTMLLabelElement>;
onAnimationEndCapture?
AnimationEventHandler<HTMLLabelElement>;
onAnimationIteration?
AnimationEventHandler<HTMLLabelElement>;
onAnimationIterationCapture?
AnimationEventHandler<HTMLLabelElement>;
onAnimationStart?
AnimationEventHandler<HTMLLabelElement>;
onAnimationStartCapture?
AnimationEventHandler<HTMLLabelElement>;
onAuxClick?
MouseEventHandler<HTMLLabelElement>;
onAuxClickCapture?
MouseEventHandler<HTMLLabelElement>;
onBlur?
(e: FocusEvent<Element, Element>) => void;
onChange?
(isSelected: boolean) => void;
onClickCapture?
MouseEventHandler<HTMLLabelElement>;
onContextMenu?
MouseEventHandler<HTMLLabelElement>;
onContextMenuCapture?
MouseEventHandler<HTMLLabelElement>;
onDoubleClick?
MouseEventHandler<HTMLLabelElement>;
onDoubleClickCapture?
MouseEventHandler<HTMLLabelElement>;
onFocus?
(e: FocusEvent<Element, Element>) => void;
onFocusChange?
(isFocused: boolean) => void;
onGotPointerCapture?
PointerEventHandler<HTMLLabelElement>;
onGotPointerCaptureCapture?
PointerEventHandler<HTMLLabelElement>;
onHoverChange?
(isHovering: boolean) => void;
onHoverEnd?
(e: HoverEvent) => void;
onHoverStart?
(e: HoverEvent) => void;
onKeyDown?
(e: KeyboardEvent) => void;
onKeyUp?
(e: KeyboardEvent) => void;
onLostPointerCapture?
PointerEventHandler<HTMLLabelElement>;
onLostPointerCaptureCapture?
PointerEventHandler<HTMLLabelElement>;
onMouseDown?
MouseEventHandler<HTMLLabelElement>;
onMouseDownCapture?
MouseEventHandler<HTMLLabelElement>;
onMouseEnter?
MouseEventHandler<HTMLLabelElement>;
onMouseLeave?
MouseEventHandler<HTMLLabelElement>;
onMouseMove?
MouseEventHandler<HTMLLabelElement>;
onMouseMoveCapture?
MouseEventHandler<HTMLLabelElement>;
onMouseOut?
MouseEventHandler<HTMLLabelElement>;
onMouseOutCapture?
MouseEventHandler<HTMLLabelElement>;
onMouseOver?
MouseEventHandler<HTMLLabelElement>;
onMouseOverCapture?
MouseEventHandler<HTMLLabelElement>;
onMouseUp?
MouseEventHandler<HTMLLabelElement>;
onMouseUpCapture?
MouseEventHandler<HTMLLabelElement>;
onPointerCancel?
PointerEventHandler<HTMLLabelElement>;
onPointerCancelCapture?
PointerEventHandler<HTMLLabelElement>;
onPointerDown?
PointerEventHandler<HTMLLabelElement>;
onPointerDownCapture?
PointerEventHandler<HTMLLabelElement>;
onPointerEnter?
PointerEventHandler<HTMLLabelElement>;
onPointerLeave?
PointerEventHandler<HTMLLabelElement>;
onPointerMove?
PointerEventHandler<HTMLLabelElement>;
onPointerMoveCapture?
PointerEventHandler<HTMLLabelElement>;
onPointerOut?
PointerEventHandler<HTMLLabelElement>;
onPointerOutCapture?
PointerEventHandler<HTMLLabelElement>;
onPointerOver?
PointerEventHandler<HTMLLabelElement>;
onPointerOverCapture?
PointerEventHandler<HTMLLabelElement>;
onPointerUp?
PointerEventHandler<HTMLLabelElement>;
onPointerUpCapture?
PointerEventHandler<HTMLLabelElement>;
onScroll?
UIEventHandler<HTMLLabelElement>;
onScrollCapture?
UIEventHandler<HTMLLabelElement>;
onTouchCancel?
TouchEventHandler<HTMLLabelElement>;
onTouchCancelCapture?
TouchEventHandler<HTMLLabelElement>;
onTouchEnd?
TouchEventHandler<HTMLLabelElement>;
onTouchEndCapture?
TouchEventHandler<HTMLLabelElement>;
onTouchMove?
TouchEventHandler<HTMLLabelElement>;
onTouchMoveCapture?
TouchEventHandler<HTMLLabelElement>;
onTouchStart?
TouchEventHandler<HTMLLabelElement>;
onTouchStartCapture?
TouchEventHandler<HTMLLabelElement>;
onTransitionCancel?
TransitionEventHandler<HTMLLabelElement>;
onTransitionCancelCapture?
TransitionEventHandler<HTMLLabelElement>;
onTransitionEnd?
TransitionEventHandler<HTMLLabelElement>;
onTransitionEndCapture?
TransitionEventHandler<HTMLLabelElement>;
onTransitionRun?
TransitionEventHandler<HTMLLabelElement>;
onTransitionRunCapture?
TransitionEventHandler<HTMLLabelElement>;
onTransitionStart?
TransitionEventHandler<HTMLLabelElement>;
onTransitionStartCapture?
TransitionEventHandler<HTMLLabelElement>;
onWheel?
WheelEventHandler<HTMLLabelElement>;
onWheelCapture?
WheelEventHandler<HTMLLabelElement>;
readOnly?
boolean;
"false"
ref?
Ref<HTMLLabelElement>;
ref.current
to null
(or call the ref with null
if you passed a callback ref).
@see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}selected?
boolean;
"false"
translate?
"yes" | "no";
value?
string;
width?
WidthProp;
"full"
Alternative components
Alternative selection controls can be used to enter decisions or declare preferences such as settings or dialogs.