Icon Button
A square button that renders a single icon with no visible label.
Import
import { IconButton } from '@matix/components/icon-button';Usage
Variants
Icon buttons come in four visual variants.
Sizes
Disabled
Notification Count
Pass count to draw a small count in the top-end corner. A count of 0 draws nothing, and a count over 99 shows as 99+. The count is hidden from assistive tech, so put it in aria-label too.
As a Link
Pass a link element to render. The button keeps the link role, so screen readers announce a link. See Button.
<IconButton aria-label="Home" render={<Link href="/" />}>
<House size="1em" aria-hidden="true" />
</IconButton>Custom Styles
Use the sx prop to override styles. Your styles always win over internal styles.
import * as stylex from '@stylexjs/stylex';
import { Heart } from 'lucide-react';
const custom = stylex.create({
round: { borderRadius: '9999px' },
});
<IconButton sx={custom.round} aria-label="Like">
<Heart size="1em" />
</IconButton>;API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | — | Required. Describes the icon's action for assistive tech |
variant | 'solid' | 'outline' | 'ghost' | 'soft' | 'ghost' | Visual style |
size | 'xs' | 'sm' | 'md' | 'lg' | 'md' | Size preset — button is square, icon scales via 1em |
count | number | — | Notification count in the corner. 0 hides it; over 99 shows 99+ |
render | ReactElement | — | Element to render in place of the <button>, e.g. a link |
disabled | boolean | — | Disables the button |
sx | StyleXStyles | — | StyleX style override |
All other props are forwarded to the underlying <button> element.
Accessibility
- Renders a native
<button>element by default. - With a link in
render, it renders that link with norole, so assistive tech announces a link, not a button. aria-labelis required — icon buttons carry no visible text, so screen readers rely on it to announce the action. TypeScript enforces this at compile time.- Disabled state applies
aria-disabledand prevents all pointer and keyboard interaction. - Focus ring is visible only on keyboard navigation (
:focus-visible) — never on mouse click. - The
xssize is 22 px high, under the 24 px target size of WCAG 2.5.8. It passes when each target has 24 px of room: put at least 2 px between adjacentxsicon buttons, and usesmor larger for dense touch layouts. - Inherits all Base UI Button accessibility behaviors, including ARIA role and keyboard handling.
Keyboard
| Key | Action |
|---|---|
Enter | Activates the button |
Space | Activates the button |