Skip to content

Icon Button

An icon-only command button with a required accessible name.

hero.tsx

Usage guidelines

  • Use IconButton for a command shown as one icon with no visible text. An action with a visible label, with or without an icon, uses Button; navigation stays on a native link.
  • Give every icon button exactly one accessible-name source: aria-label, or aria-labelledby when suitable visible text exists elsewhere. The types reject a button with neither or both.
  • Pair most icon buttons with a Tooltip that shows the same words as the name. Compose it through the render prop of TooltipTrigger. 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-label or aria-labelledby on 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; IconButton owns the button size, radius, colors, hover, disabled and focus-visible styles.
  • Omit variant for the neutral icon-button appearance. The other variants match Button. Use tone="destructive" for destructive intent; the accent variants do not take it.
  • Use className for external layout or for selectors driven by a composed primitive, such as data-pressed or data-popup-open. Do not recreate an existing variant with classes.
  • When Toggle, Menu, Popover, Tooltip or Collapsible owns the interaction state, keep that primitive outside and compose IconButton through its render prop. 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. Put iconButtonVariants on a native anchor or router link, which owns its own name and navigation.

Anatomy

tsx
tsx

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.

Default
default
primary
secondary
tertiary
ghost
Accent
secondary-accent
ghost-accent
Destructive
default
primary
secondary
tertiary
ghost
Disabled
default
primary
secondary
tertiary
variants.tsx

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.

xs
sm
md
lg
xl
sizes.tsx

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.

composition.tsx

A link that looks like an icon button stays a native anchor with the classes from iconButtonVariants. The anchor carries its own aria-label.

link.tsx

Keyboard

KeyAction
EnterorSpaceActivates the button.
TabMoves 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.

Base UI Button docs

Props
PropTypeDefaultDetails
aria-labelstringNo default
aria-labelledbystringNo default
size'lg' | 'md' | 'sm' | 'xl' | 'xs''md'
variant'default' | 'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary''default'
tone'default' | 'destructive''default'
children requiredReact.ReactElement<unknown, string | React.JSXElementConstructor<any>>No default
Base UI Button docs

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'
Data attributes
AttributeDescription
data-disabled

Present when the button is disabled.

iconButtonVariants

Parameters
ParameterTypeDescription
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