Skip to content
shadcn.io

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.

Framework
UI library

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

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 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.

Can I use default variant instead of outline?

Yes. Leave out variant="outline" and the items lose their border, appearing only on hover and when pressed, as in the Default Toggle Group example. Both variants work at every size.

How many items should a default toggle group contain?

Keep a group to a handful of related options, like the three text styles here. When a toolbar needs more, split it into several groups by purpose, such as text style, alignment and lists, rather than one long row.