Toggle
A two-state button that can be on or off.
When to use
- A button that stays pressed to show a state: a filter panel, a favourite, bold text.
When not to use
- A one-time action, such as delete or export: use Button.
- A setting that persists, such as notifications: use Switch.
- Several related toggles, such as a view switcher: use Toggle Group.
Install
npx shadcn@latest add @clinia/toggleClinia rules
- Pressed is a Trust border (
border-emphasis) over abg-accent/15tint withtext-foreground. The label never turns Trust. defaulthas no border at rest, for toolbars.outlinehas aninputborder, for a toggle that stands alone.- The label stays the same when pressed. The pressed style shows the state, so don't swap
Show filtersforHide filters.
Do and don't
States
off
pressed
outline
outline · pressed
hover
focus
disabled
Focus cells apply the component's focus-visible classes statically. Toggle the site theme to review both themes.
Sizes
| Size | Height | Padding x | Gap | Radius | Type |
|---|---|---|---|---|---|
| default | h-9 · 36px | px-3 · 12px | gap-1 · 4px | --radius-lg | text-sm · 14px |
| sm | h-8 · 32px | px-3 · 12px | gap-1 · 4px | --radius-lg | text-sm · 14px |
| lg | h-10 · 40px | px-4 · 16px | gap-1 · 4px | --radius-lg | text-sm · 14px |
Accessibility
Built in
- Pressed shows a Trust border (
border-emphasis, 3:1 or more in both themes) over abg-accent/15tint. Upstream usesbg-muted, which is 1.06:1 on the white background and does not show the state. - Base UI renders a native
buttonwitharia-pressed.
Your responsibility
- Give an icon-only toggle an
aria-labelthat names what it turns on, such asFavorite, not the action. - Don't change the
aria-labelwhen pressed:aria-pressedalready tells a screen reader the state.
How to test
- Press Tab to reach the toggle: the Trust ring appears.
- Press Enter or Space: it switches between pressed and not pressed, and the Trust border appears or goes.
- With a screen reader, it's announced as its label, then toggle button, then pressed or not pressed.
API
| Prop | Values | Default | Description |
|---|---|---|---|
| variant | defaultoutline | default |
|
| size | defaultsmlg | default | Height: |
All other props come from Base UI Toggle.
Related