# Icon Button

> A button that is only an icon.

Component · Foundations · Halo kit · [Live page](https://ui.twentyfirst.media/halo/components/IconButton/)

A button that is only an icon. `label` is required: it becomes the accessible name and the tooltip.

- Variants `soft` (default), `solid`, `outline` and `ghost`; sizes `sm`, `md` and `lg` on the control
  scale of the kit.
- `href` renders a real link with the same look (middle-click, ⌘-click and prefetch work); `linkAs`
  takes a router link such as Next.js `Link`. `asChild` puts the look and the icon on your own single
  child element instead.

```tsx
import Link from "next/link";

<IconButton icon="chevronLeft" label="Back to orders" href="/admin/orders" linkAs={Link} />
<IconButton asChild icon="download" label="Download invoice">
  <a href="/invoices/4417.pdf" download />
</IconButton>
```

## Example

```tsx
import { IconButton } from "@twentyfirstmedia/halo";

export default function Preview() {
  return (
    <div className="tf-col" style={{ gap: 20 }}>
      <div className="tf-row" style={{ gap: 8, flexWrap: "wrap" }}>
        <IconButton icon="edit" label="Edit" />
        <IconButton icon="trash" label="Delete" variant="outline" />
        <IconButton icon="more" label="More actions" variant="ghost" />
        <IconButton icon="plus" label="Add" variant="solid" />
        <IconButton icon="x" label="Close" size="sm" />
        <IconButton icon="settings" label="Settings" size="lg" />
      </div>
      <div className="tf-row" style={{ gap: 8, alignItems: "center", flexWrap: "wrap" }}>
        <IconButton icon="chevronLeft" label="Back to orders" href="#orders" variant="ghost" />
        <span style={{ color: "var(--ink-muted)" }}>Order #4417</span>
        <IconButton asChild icon="download" label="Download invoice" variant="outline">
          <a href="#invoice-4417.pdf" download />
        </IconButton>
      </div>
    </div>
  );
}
```

## Props

### IconButton

| Prop | Type | Notes |
| --- | --- | --- |
| `icon` | `IconName` | Required |
| `label` | `string` | Accessible name and tooltip (`aria-label` and `title`); `aria-label` or `title` override them. |
| `variant?` | `"soft" \| "solid" \| "outline" \| "ghost"` |  |
| `size?` | `"sm" \| "md" \| "lg"` |  |
| `type?` | `"button" \| "submit" \| "reset"` |  |
| `onClick?` | `(e: MouseEvent<HTMLButtonElement>) => void` |  |
| `disabled?` | `boolean` |  |
| `asChild?` | `boolean` | Render the single child element (a link) with the button's look; the icon is placed inside it. |
| `href?` | `string` | Render a link instead of a button (middle-click, ⌘-click, prefetch): `label` stays its accessible name and tooltip. Use `linkAs` for a router link (e.g. Next.js `Link`). |
| `linkAs?` | `ElementType` | The link component for `href` (default `a`), e.g. Next.js `Link`. |
| `children?` | `ReactNode` |  |
| `id?` | `string` |  |
| `name?` | `string` | Form field name and value, sent with the form when this button submits it. |
| `value?` | `string` |  |
| `form?` | `string` | The id of the form this button belongs to, when it sits outside it. |
| `title?` | `string` |  |
| `tabIndex?` | `number` |  |
| `autoFocus?` | `boolean` |  |
| `aria-label?` | `string` |  |
| `aria-labelledby?` | `string` |  |
| `aria-describedby?` | `string` |  |
| `aria-expanded?` | `boolean \| "true" \| "false"` | For disclosure and menu triggers: whether what the button controls is open. |
| `aria-controls?` | `string` |  |
| `aria-haspopup?` | `boolean \| "true" \| "false" \| "menu" \| "listbox" \| "tree" \| "grid" \| "dialog"` |  |
| `aria-pressed?` | `boolean \| "true" \| "false" \| "mixed"` | For toggle buttons. |
| `aria-current?` | `boolean \| "true" \| "false" \| "page" \| "step" \| "location" \| "date" \| "time"` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
