Toggle

Two-state button for toggling between on and off

Primitive

A toggle is a two-state button that stays pressed when on. Use it for a single on/off control like bold, mute, or pin. For a set of mutually exclusive or multi-select toggles, use Toggle Group; for a labeled settings switch, use Switch.

Preview

Installation

Usage

Examples

Sizes

Use size to set the toggle's height and padding.

SizeDescription
smCompact, for dense toolbars.
defaultThe standard height.
lgTaller, for prominent controls.

With Text

Put a text label beside the icon.

Variants

Use variant to set the toggle's fill.

VariantDescription
ghostThe default. No fill when off, a neutral fill when on.
softA secondary Button's fill when off, a deeper one when on.
outlineAn outline Button's fill and border, a secondary fill when on.

Custom Colors

The toggle paints its fill from CSS variables, one per state:

VariableState
--tgl-bgOff.
--tgl-bg-hoverOff and hovered.
--tgl-bg-activeOff and held down. Falls back to hover.
--tgl-bg-selectedOn.
--tgl-borderBorder color, in every state.

Each variant sets them and the toggle picks one per state, so you recolor the fill by overriding them, with no hover: or data-pressed: prefixes. Override them rather than adding bg-* to the root: a root bg-* paints behind the fill layer, where opaque variants hide it. Set the label color with a state-prefixed text class:

Custom properties can't take Tailwind's /10 opacity shorthand; build a translucent tint with color-mix:

Any variable you don't override keeps the variant's color for that state.

The border lives on the toggle's paint pseudo-element, so before: classes restyle it, for example before:border-dashed or before:border-2. Only outline sets a visible --tgl-border, so on the other variants pair those classes with a color: [--tgl-border:var(--border)] before:border-dashed.

Controlled

Use pressed and onPressedChange to drive the toggle state yourself.

Disabled

Set disabled to block interaction.

Accessibility

Labels

Give an icon-only toggle an aria-label that names what it controls, since it has no text for a screen reader to announce.

API Reference

The Toggle component is built on top of Base UI's Toggle. All Base UI props are supported. The documentation below only covers custom props and modified defaults specific to our implementation.

For the complete Base UI API, see the Base UI Toggle documentation.

Props

Toggle

A two-state button. Wraps Base UI's Toggle.

Upgrading

If you're reinstalling over an earlier version, check these changes:

BeforeNow
variant="solid"variant="soft", a secondary fill that deepens when on.
Pressed at 0.97Pressed at 0.98, as on Button.