Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Toggle examples · Sizes

Small Toggle for React

A small icon-only toggle for bold in a compact toolbar.

Framework
UI library

Inline formatting bars and comment editors don't have room for full-size controls. This React example is a bold Toggle on Base UI with size="sm", one step shorter than the default and with tighter padding. Use it in compact toolbars, side panels and dense admin screens, where more controls have to fit in a narrow space.

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

Use sm when space is tight: a formatting bar that floats over selected text, a toolbar in a sidebar, or a table header with several view options. Keep it for secondary controls, and use the default size for the main toolbar of a page.

What icon size works best with small toggles?

The Toggle sizes an icon for you (size-4 in most styles) unless the icon has its own size-* class, and that size reads well at sm. Going smaller, such as size-3, makes the icons hard to recognize, so leave the default in place.

Are small toggles accessible for touch targets?

They meet the 24 by 24 pixel minimum of WCAG 2.5.8 in every style, but they're well below the 44 pixel target recommended for touch, so they suit pointer-driven, desktop layouts best. On touch screens, use the default size or leave enough space between toggles that a tap can't hit the wrong one.

How do I group multiple small toggles together?

Use the Toggle Group with size="sm", as the Small Toggle Group example does: the size applies to every item, and the group handles pressed state and arrow-key navigation. Lower its spacing for a tighter row, or set it to 0 to join the items.

Can I add text labels to small toggle buttons?

You can, and the Toggle widens to fit, but text makes a compact toolbar wide again. Small toggles work best icon-only, each with an aria-label such as "Toggle bold". If you need labels, the default size gives them more room.

Should small toggles scale differently on mobile?

Often, yes. Pick the size from the layout rather than resizing with classes: render size="sm" in the desktop toolbar and the default size where the toolbar is used on touch screens. Test both on real devices.