Components
Switch
Toggles for turning a single setting on or off
About
Switch is built on React Aria and styled with Thumbprint v2 semantic tokens. Use it for a binary setting that takes effect immediately, such as enabling or disabling a feature or preference. When the change needs to be confirmed through a form submission, use a Checkbox instead.
Basic switch
The isChecked prop determines whether the switch is on, and onChange receives the new boolean value. Always pair a switch with an inline label that describes the feature being toggled.
function SwitchExample() { const [isChecked, setIsChecked] = React.useState(false); return ( <Switch isChecked={isChecked} onChange={setIsChecked}> Email notifications </Switch> ); }
Sizes
The size prop controls the switch dimensions. large (the default) is the 52×32 control shared with iOS; small is a 36×20 web-only control for dense layouts.
function SwitchExample() { const [isChecked, setIsChecked] = React.useState(true); return ( <Switch size="small" isChecked={isChecked} onChange={setIsChecked}> Email notifications </Switch> ); }
Disabled switches
The isDisabled prop visually and functionally disables the switch. It also visually disables the related label.
<React.Fragment> <Switch isDisabled onChange={() => {}}> Email notifications </Switch> <Switch isDisabled isChecked onChange={() => {}}> Push notifications </Switch> </React.Fragment>
Switch with a description
The description prop renders secondary text beneath the label, and the label is emphasized. Use it for settings that benefit from extra context.
function SwitchExample() { const [isChecked, setIsChecked] = React.useState(false); return ( <Switch isChecked={isChecked} onChange={setIsChecked} description="Get an email when a pro responds to your request." > Email notifications </Switch> ); }
Switch without a visible label
When the switch has no textual children (for example, a switch labeled by surrounding UI), provide an accessibilityLabel so assistive technologies can announce it.
function SwitchExample() { const [isChecked, setIsChecked] = React.useState(false); return ( <Switch isChecked={isChecked} onChange={setIsChecked} accessibilityLabel="Email notifications" /> ); }
Props
Switch
isCheckedDetermines if the switch is on. Maps to React Aria's
isSelected.TypebooleandefaultCheckedThe default on state when the switch is uncontrolled. Maps to React Aria's
defaultSelected.TypebooleanisDisabledDisables the switch and the label. A disabled switch does not accept interaction and is rendered at reduced opacity.
TypebooleanDefaultfalseisReadOnlyMakes the switch immutable while still focusable. Maps to React Aria's
isReadOnly.TypebooleanDefaultfalsechildrenText or elements that appear within the inline label. If
childrenis not provided, the developer must use theaccessibilityLabelprop to label the switch for assistive technologies.TypeReact.ReactNodedescriptionSecondary text rendered beneath the label. When provided, the label is emphasized. Maps to the
[data-has-description]attribute.TypestringsizeSets the size of the switch.
'large'(the default) is the 52×32 control used on web and iOS;'small'is the 36×20 web-only control. Maps to the[data-size]attribute.Type'small' | 'large'Default'large'idThe
idis added to the underlying switch input as an HTML attribute.TypestringnameSwitches with the same name will be grouped together when sent to the server. The browser will only send the value of switches that are on.
TypestringvalueDetermines the value that will be submitted if the switch is on. The default value is
'on'.TypestringonChangeFunction that runs when the switch is toggled. It receives the new boolean value, matching React Aria's
onChangesignature.Type(isChecked: boolean) => voidonKeyDownFunction that is called when the user presses a key while focused on the switch. Maps to React Aria's
onKeyDown.TypeAriaSwitchProps['onKeyDown']accessibilityLabelAccessible label for the switch. Only needed if non-textual children are provided (e.g., images, emojis) or no
childrenare provided. Maps to React Aria'saria-label.TypestringdataTestIdA selector hook into the React component for use in automated testing environments.
Typestring