shadcn.io is not affiliated with official shadcn/ui
Toggle Group examples · Sizes
Default Size Toggle Group for React
An outline formatting toggle group at the default size.
A formatting toolbar has to work with a mouse and on a touch screen. This React example is an outline Toggle Group on Base UI for bold, italic and underline with no size prop, so its items use the default size, md. Multiple selection lets the formats combine. It's the size to start with before going down to sm or up to lg.
Preview
Installation
FAQ
When should I use default size toggle groups?
Use the default size for most toolbars. It matches the default height of Button and Input, so the group lines up with the controls around it. Go to sm in crowded or inline toolbars, and to lg when there are only a few items and they're the main controls.
Why does default size not need a size prop?
The group's size defaults to md, and every item takes its size from the group, so leaving the prop out gives the default size. Set size on the group only for sm or lg.
Do default toggle groups need size adjustments for mobile?
Usually not, but check the targets. The default size meets the 24 pixel minimum of WCAG 2.5.8, while it's smaller than the 44 pixel touch target in most styles. Keeping the default spacing between items helps on touch screens; use size="lg" where touch is the main input.
Should I use multiple or single selection for formatting controls?
Multiple, as here: bold, italic and underline combine, so each item should stay pressed independently. Use single selection for options that exclude each other, like text alignment in the Single Selection Toggle Group example.
Related
- Small Toggle GroupA small outline formatting toggle group
- Large Toggle GroupA large outline formatting toggle group
- Default Size ToggleAn icon-only italic toggle at the default
- Default Toggle GroupA toggle group for bold, italic and
- Basic Button GroupThree rows of outline buttons joined into
- Disabled Toggle GroupA disabled toggle group of formatting