Skip to Content
Getting startedFoundationsComponentsPackagesTools

IconButton

A control that is an icon and nothing else.

Examples

Playground

Variant

Visual weight. `ghost` is the one both products use most: a bare glyph that grows a surface on hover.

primary
secondary
ghost

Tone

What the action means, at every variant (see Tone × Variant).

neutral
info
success
warning
error

Size

Three sizes, and each is measured rather than chosen. `md` is 28px, which is what **both** products already draw their default icon button at, agreeing to the pixel, and is already `control-height-sm`. Below that they disagree: core has 22px, vault has 24px and 20px. Three answers from two products is not evidence for any of them, so `sm` takes the one that is also a rule: **24px, the WCAG 2.5.8 AA minimum target size**. That makes core's 22px and vault's 20px both under the floor, and neither was ported up. `lg` is 36px, `control-height-md`, the height of a default `Button`, so an icon-only action can stand level with a labelled one beside it.

sm
md
lg

States

Every state side by side. Hover, focus and pressed are forced, so they can be reviewed without a pointer.

rest
hover
focus
pressed
loading
disabled

Tone by variant

Every combination works, as Button's does.

primarysecondaryghostneutral
info
success
warning
error

Install

npx shadcn add @hipuku/icon-button

Usage

import { IconButton } from '@/components/haus/components/IconButton'

<IconButton icon={<SettingsIcon />} label="Settings" variant="ghost" />

API

IconButton also takes the button's own attributes and forwards its ref. className lands on the root.

PropTypeDescription
iconrequiredReact.ReactNodeThe icon. Required, and the only child: an icon button with a label is a Button, and passing one here would silently produce a square control with text overflowing it.
labelrequiredstringWhat it does, for anyone who cannot see the icon. Required, because the accessible name cannot come from the content the way Button's does: an SVG contributes nothing, so without this the control announces as "button" and nothing else. Both products got this right per-site and neither had anything enforcing it.
variant"primary" | "secondary" | "ghost"
tone"neutral" | "info" | "success" | "warning" | "error"
size"sm" | "md" | "lg"
asChildfalse
loadingboolean

Variants and tones

primary, secondary and ghost, with secondary the default and ghost the one for toolbars. Every tone works at every variant, as on Button.

Sizes

sizeHeightUse it for
sm24pxDense rows. The smallest size that meets the WCAG minimum target
md28pxThe default
lg36pxBeside a default Button, so the two stand level

IconButton's sizes are one step smaller than Button's of the same name. Next to a md Button, use a lg IconButton.

Loading

loading swaps the icon for a spinner. It keeps its focus and does not run onClick while it loads. It is type="button" unless you set type="submit".

Accessibility

  • label is required: an icon has no accessible name of its own, so label is what is announced.
  • The icon is hidden from screen readers, so it never adds a second name.
  • For a link, pass the anchor as the single child with asChild. The label still applies.

On this page