Toggle
A two-state button that can be on or off.
View as MarkdownAnatomy
Import the component and use it as a single part:
import { Toggle } from '@base-ui-components/react/toggle';
<Toggle />API reference
valuestring
—
valuestring
—- Name
- Description
- A unique string that identifies the toggle when used inside a toggle group. 
- Type
- string | undefined
defaultPressedboolean
false
defaultPressedboolean
false
- Name
- Description
- Whether the toggle button is currently pressed. This is the uncontrolled counterpart of - pressed.
- Type
- boolean | undefined
- Default
- false
pressedboolean
—
pressedboolean
—- Name
- Description
- Whether the toggle button is currently pressed. This is the controlled counterpart of - defaultPressed.
- Type
- boolean | undefined
onPressedChangefunction
—
onPressedChangefunction
—- Name
- Description
- Callback fired when the pressed state is changed. 
- Type
- | (( pressed: boolean, eventDetails: Toggle.ChangeEventDetails, ) => void) | undefined
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
- Whether the component renders a native - <button>element when replacing it via the- renderprop. Set to- falseif the rendered element is not a button (e.g.- <div>).
- Type
- boolean | undefined
- Default
- true
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
- | React.CSSProperties | ((state: Toggle.State) => CSSProperties | undefined) | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
- Whether the component should ignore user interaction. 
- Type
- boolean | undefined
- Default
- false
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Toggle.State) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | ((props: HTMLProps, state: Toggle.State) => ReactElement)
data-pressed
Present when the toggle button is pressed.