Icon Button
An icon-only command button with a required accessible name.
Usage guidelines
- Use
IconButtonfor a command shown as one icon with no visible text. An action with a visible label, with or without an icon, usesButton; navigation stays on a native link. - Give every icon button exactly one accessible-name source:
aria-label, oraria-labelledbywhen suitable visible text exists elsewhere. The types reject a button with neither or both. - Pair most icon buttons with a
Tooltipthat shows the same words as the name. Compose it through therenderprop ofTooltipTrigger. A close (X) button and a "more" menu button go without one, because their icons are universally understood. - A tooltip is a visual hint, never the accessible name. Keep
aria-labeloraria-labelledbyon the button even when a tooltip shows the same text. - Pass exactly one React element as the child: the glyph, with
aria-hidden="true". The child owns the glyph and its optical size;IconButtonowns the button size, radius, colors, hover, disabled and focus-visible styles. - Omit
variantfor the neutral icon-button appearance. The other variants matchButton. Usetone="destructive"for destructive intent; the accent variants do not take it. - Use
classNamefor external layout or for selectors driven by a composed primitive, such asdata-pressedordata-popup-open. Do not recreate an existing variant with classes. - When
Toggle,Menu,Popover,TooltiporCollapsibleowns the interaction state, keep that primitive outside and composeIconButtonthrough itsrenderprop. The owner keeps its pressed, open and expanded state, events and ref; do not mirror that state on the icon button. - Do not render navigation through
IconButton, whose button behavior is for commands. PuticonButtonVariantson a native anchor or router link, which owns its own name and navigation.
Anatomy
Examples
Variants and tones
The default variant is neutral and suits dense toolbars. primary, secondary, secondary-accent, tertiary, ghost and ghost-accent match Button. Every variant except the two accent ones also takes tone="destructive". A disabled button keeps its variant and dims.
Sizes
xs through xl set the button box and radius. Size the glyph in its own class; the larger sizes fit a size-4 or size-5 icon.
Composing with a stateful primitive
Toggle owns the pressed state of the pin button and Menu owns the open state of the "more" button; each renders IconButton through render. The pin button keeps a constant name and reports its state through aria-pressed. The "more" button has no tooltip.
Icon link
A link that looks like an icon button stays a native anchor with the classes from iconButtonVariants. The anchor carries its own aria-label.
Keyboard
| Key | Action |
|---|---|
| EnterorSpace | Activates the button. |
| Tab | Moves focus to the next control. A disabled button leaves the tab order unless focusableWhenDisabled is set. |
API reference
IconButton
An icon-only command button that requires a single icon element and an accessible name. Renders a <button> element.
Requires aria-label or aria-labelledby.
| Prop | Type | Default | Details |
|---|---|---|---|
aria-label | string | No default | |
aria-labelledby | string | No default | |
size | 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'md' | |
variant | 'default' | 'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary' | 'default' | |
tone | 'default' | 'destructive' | 'default' | |
children required | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
className | string | ((state: ButtonState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ButtonState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ButtonState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
focusableWhenDisabled | boolean | false | |
Valid prop combinations:
aria-label: string,aria-labelledby?: undefined,variant?: 'default' | 'ghost' | 'primary' | 'secondary' | 'tertiary',tone?: 'default' | 'destructive'aria-label: string,aria-labelledby?: undefined,variant: 'ghost-accent' | 'secondary-accent',tone?: 'default'aria-label?: undefined,aria-labelledby: string,variant?: 'default' | 'ghost' | 'primary' | 'secondary' | 'tertiary',tone?: 'default' | 'destructive'aria-label?: undefined,aria-labelledby: string,variant: 'ghost-accent' | 'secondary-accent',tone?: 'default'
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
iconButtonVariants
| Parameter | Type | Description |
|---|---|---|
props | (ConfigVariants<{ variant: { default: string[]; primary: string[]; secondary: string[]; 'secondary-accent': string[]; tertiary: string[]; ghost: string[]; 'ghost-accent': string[]; }; tone: { default: string; destructive: string; }; size: { xs: string; sm: string; md: string; lg: string; xl: string; }; }> & ClassProp) | No description |
Returns
string