Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Toggle examples · Sizes

Default Size Toggle for React

An icon-only italic toggle at the default size.

Framework
UI library

Most toolbars need one toggle size that works with a mouse and on a touch screen. This React example is an italic Toggle on Base UI with no size prop, so it uses the default, md. It's the size to start with for formatting toolbars, editors and filters, before reaching for sm in a crowded bar or lg for a prominent control.

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 toggles?

Use the default size unless you have a reason not to. It matches the default Button and Input heights, so a toggle lines up with the controls around it. Switch to sm when the toolbar is crowded or sits inside dense content, and to lg when there are only a few toggles and they're the main controls.

Why does default size not need a size prop?

The Toggle's size defaults to md, so leaving it out gives the default size. Writing size="md" does the same and only adds noise; set size only for sm or lg.

Are default size toggles accessible for touch targets?

They meet the 24 by 24 pixel minimum of WCAG 2.5.8, but in most styles they're smaller than the 44 pixel target recommended for touch. On touch-first screens, leave space between toggles or use size="lg", and test on a real device.

Can default toggles include both icon and text?

Yes. Put the text after the icon inside the Toggle, as the Toggle with Text example does; the Toggle grows to fit and keeps a gap between them. With visible text, the aria-label is no longer needed.

How do I group multiple default toggles in a toolbar?

Use the Toggle Group, as the Default Size Toggle Group example does: it tracks which items are pressed, makes the row a single Tab stop with arrow-key navigation, and passes one size and variant to every item. Its spacing sets the gap between items, and 0 joins them into one bar.

Should I mix toggle sizes in the same toolbar?

No. Toggles of different heights in one row look misaligned and suggest a hierarchy that isn't there. Keep one size per toolbar, and use the variant, order or a separator to set groups of actions apart.