---
title: Toggle Group
description: A set of two-state buttons that can be toggled on or off.
base: base
component: true
links:
  doc: https://www.radix-ui.com/docs/primitives/components/toggle-group
  api: https://www.radix-ui.com/docs/primitives/components/toggle-group#api-reference
---

<ComponentPreview styleName="base-nova" name="toggle-group-spacing" />

## Installation

<CodeTabs>

<TabsList>
  <TabsTrigger value="cli">CLI</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">

```bash
npx shadcn@latest add toggle-group
```

</TabsContent>

<TabsContent value="manual">

<Steps>

<Step>Install the following dependencies:</Step>

```bash
npm install @base-ui/react
```

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource
  name="toggle-group"
  title="components/ui/toggle-group.tsx"
  styleName="base-nova"
/>

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</CodeTabs>

## Usage

```tsx
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
```

```tsx
<ToggleGroup type="single">
  <ToggleGroupItem value="a">A</ToggleGroupItem>
  <ToggleGroupItem value="b">B</ToggleGroupItem>
  <ToggleGroupItem value="c">C</ToggleGroupItem>
</ToggleGroup>
```

## Examples

### Outline

<ComponentPreview
  styleName="base-nova"
  name="toggle-group-outline"
  description="A toggle group using the outline variant."
/>

### Single

<ComponentPreview
  styleName="base-nova"
  name="toggle-group-single"
  description="A toggle group with single selection."
/>

### Small

<ComponentPreview
  styleName="base-nova"
  name="toggle-group-sm"
  description="A toggle group using the small size."
/>

### Large

<ComponentPreview
  styleName="base-nova"
  name="toggle-group-lg"
  description="A toggle group using the large size."
/>

### Disabled

<ComponentPreview
  styleName="base-nova"
  name="toggle-group-disabled"
  description="A disabled toggle group."
/>

### Spacing

Use `spacing={2}` to add spacing between toggle group items.

<ComponentPreview
  styleName="base-nova"
  name="toggle-group-spacing"
  description="A toggle group with spacing."
/>

## API Reference

### ToggleGroup

The main component that wraps toggle group items.

| Prop        | Type                        | Default     |
| ----------- | --------------------------- | ----------- |
| `type`      | `"single" \| "multiple"`    | `"single"`  |
| `variant`   | `"default" \| "outline"`    | `"default"` |
| `size`      | `"default" \| "sm" \| "lg"` | `"default"` |
| `spacing`   | `number`                    | `0`         |
| `className` | `string`                    |             |

```tsx
<ToggleGroup type="single" variant="outline" size="sm">
  <ToggleGroupItem value="a">A</ToggleGroupItem>
  <ToggleGroupItem value="b">B</ToggleGroupItem>
</ToggleGroup>
```

### ToggleGroupItem

Individual toggle items within a toggle group. Remember to add an `aria-label` to each item for accessibility.

| Prop        | Type     | Default  |
| ----------- | -------- | -------- |
| `value`     | `string` | Required |
| `className` | `string` |          |
