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.
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
Installation
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.
Related
- Default Size Toggle GroupAn outline formatting toggle group at the
- Large Toggle GroupA large outline formatting toggle group
- Small ToggleA small icon-only toggle for bold in a
- Default Toggle GroupA toggle group for bold, italic and
- Disabled Toggle GroupA disabled toggle group of formatting
- Outline Toggle GroupAn outline toggle group for bold, italic