Make your AI a shadcn expert

Shadcn Toggle Group

React toggle group for formatting toolbars and view switchers. Built with TypeScript and Tailwind CSS for Next.js using Base UI — single or multiple, outline, and RTL.

A toggle group is a row of two-state buttons that share one value. type="single" keeps one pressed; type="multiple" lets them combine. Use it for alignment, formatting, or a list/grid switcher — a lone on/off is a Toggle.

Scroll to load preview...

Looking for a neobrutalism version for shadcn?

Same toggle group, thicker borders. The NeoBrutalism toggle group is the kit if you want that look.

Usage

import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
<ToggleGroup type="single" defaultValue="center">
  <ToggleGroupItem value="left" aria-label="Align left">Left</ToggleGroupItem>
  <ToggleGroupItem value="center" aria-label="Align center">Center</ToggleGroupItem>
  <ToggleGroupItem value="right" aria-label="Align right">Right</ToggleGroupItem>
</ToggleGroup>

type is required. The value is a string for single and a string[] for multiple.

Composition

ToggleGroupItem
ToggleGroupItem

Outline

variant="outline" puts a border on idle items so the group does not vanish into the page.

Scroll to load preview...

Size

size on the group — sm, default, or lg. Every item inherits it.

Scroll to load preview...

Spacing

spacing={0} is the connected segmented look. A number adds a gap between items.

Scroll to load preview...

Vertical

orientation="vertical" stacks the items. Pair it with spacing so the horizontal corner radii do not fuse them.

Scroll to load preview...

Disabled

disabled on the group greys every item. They stay in the row so the gap is obvious.

Scroll to load preview...

Custom

A Field plus large tiles. Control the value so the description can echo it.

Scroll to load preview...

RTL

Wrap with DirectionProvider and dir="rtl". Labels stay Arabic.

Scroll to load preview...

API

Prop

Type

ToggleGroupItem

Prop

Type

data-state is "on" or "off". variant and size on an item are fallbacks if the group did not set them.

Keyboard

KeyAction
TabFocus the pressed item, or the first
Space / EnterToggle the focused item
ArrowRight / ArrowDownNext item
ArrowLeft / ArrowUpPrevious item
Home / EndFirst / last item

Notes

Single can clear to nothing

Clicking the pressed item in type="single" sets the value to "". Ignore empty strings in onValueChange if one must stay on.

Name every icon-only item. aria-label="Toggle bold" — a bare icon is just “button”.

With other components

Questions

Was this page helpful?

Sign in to leave feedback.