shadcn.io is not affiliated with official shadcn/ui
Toggle Group examples · Standard
Outline Toggle Group for React
An outline toggle group for bold, italic and underline.
A formatting toolbar on a busy surface needs buttons with an edge. This React example is a Toggle Group on Base UI with variant="outline", so every item gets a border, and multiple selection, so bold, italic and underline can be on together. Pressed items fill with the muted background. The variant is set once on the group, and each item follows it.
Preview
Installation
FAQ
What's the visual difference between default and outline variants?
Both variants are transparent while unpressed and fill with the muted background when pressed. The default variant has no border, so the items only appear on hover or when pressed; the outline variant adds a border in the input border color, so each item reads as a button from the start.
Are outline toggle groups accessible with sufficient contrast?
The variant doesn't change how the group is announced or used from the keyboard. For contrast, the input border color is meant to be visible against the background in both light and dark themes; if you change it, keep at least 3:1 against the surface, and check the pressed fill as well, since it's what tells pressed and unpressed apart.
Can I customize the outline border colors?
Yes. Add a border class to each ToggleGroupItem, such as border-primary, or style the pressed item only.
The pressed item has data-pressed, so use data-pressed:border-primary.
When should I use outline instead of default toggle groups?
Use the outline variant when the group sits on a busy or tinted surface, when the buttons need to be visible before anyone hovers them, or when nearby buttons are outline too. Use the default variant inside a toolbar that already has its own frame, where a border on every item adds noise.
Does the outline variant work with both single and multiple selection?
Yes. The variant only changes the look, and the selection mode only changes the behavior. This example allows multiple selection; the Single Selection Toggle Group example uses the outline variant with one pressed item at a time.
Do outline toggle groups work well on mobile devices?
Yes. The border helps people see the targets on small screens and in bright light. The default size is still smaller than the 44 pixel touch target in most styles, so on touch-first screens use size="lg" or keep the default spacing between items so a tap can't land on the wrong one.
Related
- Default Toggle GroupA toggle group for bold, italic and
- Single Selection Toggle GroupAn outline toggle group for text
- Disabled Toggle GroupA disabled toggle group of formatting
- Outline ToggleAn outline toggle for italic with a
- Button with Text (Outline)A border, no fill
- Default Size Toggle GroupAn outline formatting toggle group at the