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.
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
Installation
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.
Related
- Default Size ToggleAn icon-only italic toggle at the default
- Large ToggleA large icon-only toggle for underline
- Small Toggle GroupA small outline formatting toggle group
- Default ToggleAn icon-only toggle that turns bold on
- Disabled ToggleA disabled icon-only toggle for underline
- Outline ToggleAn outline toggle for italic with a