Switch

A control that indicates whether a setting is on or off.

import * as React from 'react';
import { Switch } from '@base-ui-components/react/switch';
import styles from './index.module.css';

export default function ExampleSwitch() {
  return (
    <Switch.Root defaultChecked className={styles.Switch}>
      <Switch.Thumb className={styles.Thumb} />
    </Switch.Root>
  );
}

API reference

Import the component and place its parts the following way:

Anatomy
import { Switch } from '@base-ui-components/react/switch';

<Switch.Root>
  <Switch.Thumb />
</Switch.Root>

Root

The foundation for building custom-styled switches.

PropTypeDefault
checkedbooleanundefined
classNamestring | (state) => stringundefined
defaultCheckedbooleanfalse
disabledbooleanfalse
inputRefReact.Refundefined
namestringundefined
onCheckedChange(checked, event) => voidundefined
readOnlybooleanfalse
render| React.ReactElement
| (props, state) => React.ReactElement
undefined
requiredbooleanfalse

Thumb

PropTypeDefault
classNamestring | (state) => stringundefined
render| React.ReactElement
| (props, state) => React.ReactElement
undefined