Skip to Content
Documentation
Getting startedComponentsChartsTheming
Get Pro
Overview
Concepts

Toggle

Used to create a button that can be toggled on and off.

Anatomy

import { Toggle } from '@chakra-ui/react'
<Toggle.Root>
  <Toggle.Indicator />
</Toggle.Root>

The Toggle.Root renders a button element. Use the asChild prop to render it as any other button component, like the Button component.

Examples

Basic

Use the _pressed condition to style the toggle when it is pressed. Since the toggle renders a button, the asChild prop lets you reuse the Button component and its variants.

Indicator

Use the Toggle.Indicator component to render different content based on the pressed state. Pass the unpressed content to the fallback prop, and the pressed content as children.

Pressed Icon

Render a Toggle.Indicator without a fallback to only show an icon when the toggle is pressed. The colorPalette prop also accepts the _pressed condition.

Controlled

Use the pressed and onPressedChange props to control the pressed state programmatically.

Pressed: false

Props

Root

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
defaultPressed
boolean

The default pressed state of the toggle.

onPressedChange
(pressed: boolean) => void

Event handler called when the pressed state of the toggle changes.

pressed
boolean

The pressed state of the toggle.

Indicator

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
fallback
string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<...>

The fallback content to render when the toggle is not pressed.