Toggle
Toggle is a button that switches between on/off states. Use standalone or group with ToggleGroup.
4
Variants
5
Sizes
on/off
States
Radix
Base
Playground
Preview
defaultD40px / 14pxIcon 16px
Variant
Size
Radius
Icon
Label
Weight
State
const [starred, setStarred] = useState(false)
<Toggle
pressed={starred}
onPressedChange={setStarred}
iconOnly
aria-label={starred ? "Unstar" : "Star"}
>
<Star
className={`transition-colors ${
starred ? "fill-yellow-500 text-yellow-500" : ""
}`}
/>
</Toggle>Variants
Default
Background changes on press — ideal for toolbars and compact UI
Outline
Bordered style — state is clearly visible
Ghost
No background change — state shown through icon color only, ideal for like buttons
Outline Ghost
Border + icon-only state — clear boundary with minimal visual change
Sizes
Icon Only (iconOnly=true)
xsSize28px × 28px
Icon14px
smSize32px × 32px
Icon16px
mdSize36px × 36px
Icon16px
defaultSize40px × 40px
Icon20px
lgSize48px × 48px
Icon24px
| Size | Size | Icon | Preview |
|---|---|---|---|
xs | 28px × 28px | 14px | |
sm | 32px × 32px | 16px | |
md | 36px × 36px | 16px | |
default | 40px × 40px | 20px | |
lg | 48px × 48px | 24px |
Icon + Text (iconOnly=false)
xsHeight28px
H Padding10px
Gap4px
Icon14px
Font12px
smHeight32px
H Padding12px
Gap8px
Icon14px
Font13px
mdHeight36px
H Padding14px
Gap8px
Icon16px
Font14px
defaultHeight40px
H Padding16px
Gap8px
Icon16px
Font14px
lgHeight48px
H Padding24px
Gap8px
Icon16px
Font16px
| Size | Height | H Padding | Gap | Icon | Font | Preview |
|---|---|---|---|---|---|---|
xs | 28px | 10px | 4px | 14px | 12px | |
sm | 32px | 12px | 8px | 14px | 13px | |
md | 36px | 14px | 8px | 16px | 14px | |
default | 40px | 16px | 8px | 16px | 14px | |
lg | 48px | 24px | 8px | 16px | 16px |
States
Off
On
Disabled
Disabled On
<Toggle iconOnly variant="outline" aria-label="Off"><Star className="icon-xl" /></Toggle>
<Toggle iconOnly variant="outline" defaultPressed aria-label="On"><Star className="icon-xl fill-yellow-500 text-yellow-500" /></Toggle>
<Toggle iconOnly variant="outline" disabled aria-label="Disabled"><Star className="icon-xl" /></Toggle>
<Toggle iconOnly variant="outline" disabled defaultPressed aria-label="Disabled on"><Star className="icon-xl fill-yellow-500 text-yellow-500" /></Toggle>API
Props
pressedundefinedbooleanOn/off state for controlled mode
defaultPressedfalsebooleanInitial state for uncontrolled mode
onPressedChangeundefined(pressed: boolean) => voidCallback on state change
variant"default""default" | "outline" | "ghost" | "outline-ghost"Visual style. ghost/outline-ghost have no background change (icon color only)
size"default""xs" | "sm" | "md" | "default" | "lg"Toggle size (28/32/36/40/48px)
radius"default""none" | "sm" | "base" | "default" | "lg" | "xl" | "2xl" | "3xl" | "full"Border radius (6px)
fontWeight"normal""normal" | "semibold"Font weight. normal=400, semibold=600
iconOnlyundefinedbooleanIcon-only mode. Square layout with IconButton sizing rules
pressEffectundefinedbooleanPress effect (active:scale-pressed). Defaults to true. Set false to disable
disabledfalsebooleanDisabled state
asChildfalsebooleanRender as Slot
| Name | Type | Default | Description |
|---|---|---|---|
pressed | boolean | undefined | On/off state for controlled mode |
defaultPressed | boolean | false | Initial state for uncontrolled mode |
onPressedChange | (pressed: boolean) => void | undefined | Callback on state change |
variant | "default" | "outline" | "ghost" | "outline-ghost" | "default" | Visual style. ghost/outline-ghost have no background change (icon color only) |
size | "xs" | "sm" | "md" | "default" | "lg" | "default" | Toggle size (28/32/36/40/48px) |
radius | "none" | "sm" | "base" | "default" | "lg" | "xl" | "2xl" | "3xl" | "full" | "default" | Border radius (6px) |
fontWeight | "normal" | "semibold" | "normal" | Font weight. normal=400, semibold=600 |
iconOnly | boolean | undefined | Icon-only mode. Square layout with IconButton sizing rules |
pressEffect | boolean | undefined | Press effect (active:scale-pressed). Defaults to true. Set false to disable |
disabled | boolean | false | Disabled state |
asChild | boolean | false | Render as Slot |
Anatomy
1
2
3
Favorite
state
data-[state=on/off]1
Container
Toggle button body
2
Icon
Optional
3
Label
Optional
Best Practices
✓
Recommended
- ✓Visually indicate clear on/off states
- ✓Describe purpose with aria-label
- ✓Use for immediate-effect actions
- ✓Group multiple toggles with ToggleGroup
✕
Avoid
- ✗Don't use for form items that need submission
- ✗Don't use icons with unclear state indication
- ✗Don't use without aria-label
- ✗Use Segmented for exclusive selection
Accessibility
Keyboard
SpaceToggle
EnterToggle
ARIA Attributes
aria-pressedAuto-applieddata-stateon/off- Focus indicator
aria-labelRecommended