Toggle Group
A group of toggle buttons where one or multiple can be selected.
When to Use
Use Toggle Group when you need to:
- Let users select one option from a small set of mutually exclusive choices (e.g., text alignment)
- Allow multiple selections from a set of related options (e.g., text formatting: bold, italic, underline)
- Provide a compact toolbar-style control for view modes or layout options
- Replace radio buttons when you need a more visual, icon-driven selection interface
- Create segmented controls for filtering, sorting, or switching display modes
When Not to Use
- Single on/off toggle - use Toggle or Switch
- More than 5-6 options - use Select or Radio Group
- Navigation between views - use Tabs instead
- Actions that trigger side effects - use Button or Button Group
Default
Toggle group with spacing, outline variant, and custom pressed state styling.
Outline
Outline variant with visible borders and joined items (spacing 0).
Single Selection
With type="single", only one item can be pressed at a time. Ideal for mutually exclusive options like text alignment.
Sizes
Available size options: sm, default, and lg. Size is applied uniformly to all items in the group.
Disabled
Disabled toggle group prevents all interaction. Individual items can also be disabled independently.
Controlled
Controlled toggle group with external state management via value and onValueChange props.
Selected: bold
UX & Design Guidelines
Visual Hierarchy
Use variant="default" for subtle toggle groups that blend into the interface, and variant="outline" when the group needs to stand out with clear visual boundaries. Choose type="single" for mutually exclusive selections and type="multiple" when users can combine options.
Spacing & Layout
Use spacing={0} (default) for joined items that visually form a single control, ideal for toolbar-style groups. Use spacing={2} or higher to separate items for better visual distinction. When items have both icons and labels, ensure consistent content across all items.
Responsive Behavior
On mobile, consider using size="lg" for better touch targets (minimum 44x44px). For groups with many items, consider wrapping to a second line or switching to a Select on narrow screens. Icon-only items work best on small screens while icon-with-label is preferable on desktop.
Color & Contrast
Pressed items use bg-accent with text-accent-foreground for clear visual feedback. The outline variant adds border-input for additional definition. Disabled states reduce opacity to 50% while maintaining readability. Use data-[state=on]: selectors for custom pressed-state styling.
Accessibility
Keyboard Navigation
- Tab -- Move focus into and out of the toggle group
- ArrowRight / ArrowDown -- Move focus to the next item
- ArrowLeft / ArrowUp -- Move focus to the previous item
- Space or Enter -- Toggle the focused item on or off
- Home -- Move focus to the first item
- End -- Move focus to the last item
Screen Reader Support
- Built on Radix UI ToggleGroup primitive with full ARIA support
- Uses
role="group"on the container for screen readers - Each item announces its pressed state (
aria-pressed) - Icon-only items require
aria-labelfor accessible names - Add
aria-labelto the group itself to describe its purpose
Focus Management
Focus is managed as a roving tabindex within the group. Only one item is in the tab order at a time; arrow keys move focus between items. Visible focus ring with 3px width using focus-visible:ring-[3px]. Focused items get z-10 to ensure the focus ring is not clipped by adjacent items.
Touch Targets
Default size items are 36px height (h-9), meeting minimum touch target recommendations. Use size="lg" (44px) for critical touch interactions on mobile. Items with spacing={0} share borders but maintain individual touch targets.
ARIA Attributes
{/* Single selection group with accessible label */}
<ToggleGroup type="single" aria-label="Text alignment">
<ToggleGroupItem value="left" aria-label="Align left">
<AlignLeft className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="center" aria-label="Align center">
<AlignCenter className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="right" aria-label="Align right">
<AlignRight className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
{/* Multiple selection group */}
<ToggleGroup type="multiple" aria-label="Text formatting">
<ToggleGroupItem value="bold" aria-label="Toggle bold">
<Bold className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="italic" aria-label="Toggle italic">
<Italic className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="underline" aria-label="Toggle underline">
<Underline className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
{/* Disabled item within a group */}
<ToggleGroup type="multiple" aria-label="Text options">
<ToggleGroupItem value="bold" aria-label="Toggle bold">
<Bold className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="strikethrough" disabled aria-label="Toggle strikethrough (unavailable)">
<Strikethrough className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>Related Components
API Reference
The ToggleGroup component accepts the following props in addition to standard div attributes.
| Prop | Type | Default | Description |
|---|---|---|---|
| type | "single" | "multiple" | "single" | Determines whether one or multiple items can be pressed at a time. |
| value | string | string[] | — | The controlled value of the pressed item(s). |
| defaultValue | string | string[] | — | The default value when initially rendered (uncontrolled). |
| onValueChange | (value: string | string[]) => void | — | Event handler called when the value changes. |
| variant | "default" | "outline" | "default" | The visual style variant applied to all items in the group. |
| size | "default" | "sm" | "lg" | "default" | The size of the toggle group items. |
| spacing | number | 0 | Gap spacing between items (in Tailwind spacing units). When 0, items share borders. |
| disabled | boolean | false | When true, prevents user interaction with all items in the group. |
| className | string | — | Additional CSS classes to apply to the toggle group container. |
ToggleGroupItem API
Individual toggle items within a ToggleGroup. Inherits variant and size from the parent group.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | — | A unique value for the item (required). |
| disabled | boolean | false | When true, prevents user interaction with this item. |
| aria-label | string | — | Accessible label (required for icon-only items). |
| className | string | — | Additional CSS classes to apply to the toggle group item. |