shadcn.io is not affiliated with official shadcn/ui
Toggle examples · Standard
Outline Toggle for React
An outline toggle for italic with a border around it.
The default Toggle has no border, which can make it hard to spot on a busy surface. This React example sets variant="outline" on an italic Toggle built on Base UI: a thin border marks the button while it's off, and the pressed state fills the background. Use it in toolbars where buttons need an edge to read as buttons, or to match outline buttons nearby.
Preview
Installation
FAQ
What's the visual difference between default and outline variants?
Both are transparent while unpressed and fill with the muted background when pressed. The default variant has no border; the outline variant adds a border in the input border color, so the button is visible even before it's hovered or pressed. The difference is mostly in the unpressed state.
Can I customize the outline border color?
Yes. Add a border class on the Toggle, such as border-primary, and use the aria-pressed: variant for the pressed state, such as aria-pressed:border-primary. Use theme tokens rather than fixed palette colors so the border follows light and dark mode, and keep at least 3:1 contrast against the background.
Are outline toggles as accessible as default toggles?
Yes. The variant only changes the styles; the button, its aria-label and its pressed state are announced the same way. The border actually helps people find the control, as long as it has enough contrast with the surface behind it.
Why does the pressed state fill the background on outline toggles?
A change of border alone is easy to miss. Filling the background makes pressed and unpressed clearly different at a glance, and it matches the default variant, so both look the same once they're on. To change it, style the aria-pressed attribute on the Toggle.
When should I use outline toggles instead of default?
Use the outline variant when the toggles sit on a busy or similarly colored surface, when they need to look like buttons before they're pressed, or when the toolbar mixes them with outline buttons. Use the default variant in a toolbar that already has its own frame, where borders on every button would add noise.
Can I mix outline and default toggles in the same ToggleGroup?
No: the variant is set on the ToggleGroup, and every ToggleGroupItem takes it from the group, which keeps a group consistent. If two sets of options need different weights, use two groups, one with variant="outline" and one without, as the Outline Toggle Group and Default Toggle Group examples show.
Related
- Default ToggleAn icon-only toggle that turns bold on
- Toggle with TextA toggle with a bold icon and a visible
- Outline Toggle GroupAn outline toggle group for bold, italic
- Disabled ToggleA disabled icon-only toggle for underline
- Button with Text (Outline)A border, no fill
- Default Size ToggleAn icon-only italic toggle at the default