Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Toggle Group examples · Sizes

Small Toggle Group for React

A small outline formatting toggle group for compact toolbars.

Framework
UI library

Inline formatting bars and comment editors have little room, but they still need bold, italic and underline. This React example is an outline Toggle Group on Base UI with size="sm" set on the group, so every item is one step shorter than the default, with multiple selection so the formats combine.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

When should I use small toggle groups?

Use sm when space is tight: a toolbar that floats over selected text, a narrow sidebar, a popover editor or a table header. Keep the default size for the main toolbar of a page.

Why use multiple selection instead of single for toggle groups?

Because the options here combine: text can be bold, italic and underlined at once, so each item stays pressed on its own. Single selection, where pressing one item releases the others, is for options that exclude each other, like alignment.

Why use variant outline for small toggle groups?

At a small size, the border marks each item as a separate button, which helps when the icons are close together. The default variant, with no border, also works and suits a toolbar that already has its own frame.

How does ToggleGroup handle spacing between small items?

The group's spacing sets the gap between items, 2 by default, whatever the size. Lower it for a tighter row, or set it to 0 to join the items into one bar where the outline borders are shared.

Are small toggle groups accessible on mobile touchscreens?

They meet the 24 pixel minimum of WCAG 2.5.8, but they're well under the 44 pixel touch target, so they suit pointer-driven layouts best. On touch screens, use the default size or keep enough spacing between items that a tap can't hit the wrong one.

What happens when small toggle groups exceed screen width?

The group is a single row that doesn't wrap, so too many items overflow their container. Keep the group short, add flex-wrap to the group's class, or set orientation="vertical" to stack the items.