Skip to content
shadcn.io is not affiliated with official shadcn/ui

Shadcn Toggle Group for React and Tailwind

Toggle buttons for selecting a value.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/toggle-group.json

Anatomy

ToggleGroup
└── ToggleGroupItem

Usage

import { 
  ToggleGroup, 
  ToggleGroupItem 
} from "@/components/ui/toggle-group"; 
<ToggleGroup>
  <ToggleGroupItem value="1">Item 1</ToggleGroupItem>
  <ToggleGroupItem value="2">Item 2</ToggleGroupItem>
</ToggleGroup>

Controlled

Use the value and onValueChange props to control the toggle group state programmatically.

States

Disabled

Disable the entire group with the disabled prop.

With disabled toggle

Disable individual toggles by setting disabled on a specific item.

Orientation

Use orientation to change the orientation of the toggle group.

Horizontal

Vertical

Variant

Use variant to change the visual style of the toggle buttons.

Ghost

Outline

Examples

With spacing

Use spacing to add space between buttons.

Single selection

Use multiple={false} to allow only one toggle to be selected at a time.

Custom toggle group

A custom toggle group example with a custom styling for font weight selection.

API Reference

ToggleGroup

Root component. Provides shared variant and size to child toggles via context.

PropTypeDefault
variant"outline" | "ghost""ghost"
size"sm" | "md" | "lg""md"
spacing"0" | "1" | "2" | "3" | "4" | "5" | "6" | "8" | "10""0"
multiplebooleantrue
defaultValuestring[]-
valuestring[]-
onValueChange(details: ValueChangeDetails) => void-
orientation"horizontal" | "vertical""horizontal"
disabledbooleanfalse
classNamestring-
AttributeDefault
--gapSet from the spacing prop (default 0)

ToggleGroupItem

Single toggle in the group. Uses Toggle internally.

PropTypeDefault
valuestringrequired
disabledbooleanfalse
classNamestring-
aria-labelstring-

For a complete list of props, see the Ark UI documentation.