# Icon

Inline Lucide SVG icons sized by a token, icon and label buttons, and icon-only buttons with a name and a tooltip.

_Diagram: Icons sit inside buttons in a toolbar above the content: beside the label of a labelled button, and alone in a square icon-only button whose tooltip shows its name._

## Live example

### Icon and label

```html
<div class="cluster">
  <button type="button">
    <!-- Lucide: search -->
    <svg data-icon xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
      <path d="m21 21-4.34-4.34" />
      <circle cx="11" cy="11" r="8" />
    </svg>
    Search
  </button>
  <a href="#main" data-button="quiet">
    <!-- Lucide: arrow-left -->
    <svg data-icon="mirror" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
      <path d="m12 19-7-7 7-7" />
      <path d="M19 12H5" />
    </svg>
    Back
  </a>
</div>
```

### Icon only, with a tooltip

```html
<div class="cluster">
  <dui-tooltip>
    <button type="button" data-button="quiet icon">
      <!-- Lucide: search -->
      <svg data-icon xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
        <path d="m21 21-4.34-4.34" />
        <circle cx="11" cy="11" r="8" />
      </svg>
      <span class="visually-hidden">Search</span>
    </button>
    <span popover="hint" role="tooltip" aria-hidden="true">Search</span>
  </dui-tooltip>
  <dui-tooltip>
    <button type="button" data-button="quiet icon">
      <!-- Lucide: x -->
      <svg data-icon xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
        <path d="M18 6 6 18" />
        <path d="m6 6 12 12" />
      </svg>
      <span class="visually-hidden">Close</span>
    </button>
    <span popover="hint" role="tooltip" aria-hidden="true">Close</span>
  </dui-tooltip>
  <dui-tooltip>
    <button type="button" data-button="quiet icon">
      <!-- Lucide: ellipsis -->
      <svg data-icon xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
        <circle cx="12" cy="12" r="1" />
        <circle cx="19" cy="12" r="1" />
        <circle cx="5" cy="12" r="1" />
      </svg>
      <span class="visually-hidden">More actions</span>
    </button>
    <span popover="hint" role="tooltip" aria-hidden="true">More actions</span>
  </dui-tooltip>
</div>
```

### Navigation keeps its text

```html
<nav aria-label="Example" data-nav="vertical">
  <ul>
    <li>
      <a href="#nav-title">
        <!-- Lucide: house -->
        <svg data-icon xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
          <path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8" />
          <path d="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
        </svg>
        Home
      </a>
    </li>
  </ul>
</nav>
```

## Attributes

`data-icon` on an inline `<svg>` copied from [Lucide](https://lucide.dev); `data-icon="mirror"` flips a directional icon in right-to-left text

| Attribute or value | Where | Effect |
| --- | --- | --- |
| `data-icon` | an inline `<svg>` | sized `--dui-size-icon`, never shrunk, colored by currentColor |
| `data-icon="mirror"` |  | also flipped in right-to-left text: directional icons only (arrows, chevrons, undo, redo) |

An inline \<svg> icon, copied from Lucide and pasted into the page. domestic-ui ships no icon files, sprite, font or package: the SVG markup is the icon. Lucide draws with stroke="currentColor", so the icon takes the text color of whatever holds it, in every theme and in forced colors mode, where the browser forces color to a system color.

Copy the SVG from lucide.dev, replace its class attribute with data-icon, and add aria-hidden="true" focusable="false". Keep the rest as Lucide ships it (width and height keep the icon small if CSS fails to load).

- **Our choice:** the field's error text starts with the word "Error:" in the markup, rather than a CSS icon, so every user and every screen reader gets it with no extra API. Invalid controls also get a 3px halo around them, a shape change as well as a color change.
- **Our choice:** icons are [Lucide](https://lucide.dev) SVGs pasted inline, with no icon files, sprite, font or package in the repository, because Lucide already draws in our 24px, 2px, `currentColor` stroke and inline SVG needs no build and follows forced colors. The hook is `data-icon` on the `<svg>`, the same one-attribute rule as every atom, rather than `svg[aria-hidden]`, which would also style meaningful `role="img"` graphics and tie the look to an accessibility attribute. The rules for when to use an icon are in [PRINCIPLES.md](https://domestic-ui.odonckers.dev/principles/opinions-we-hold.md#icons).
- **Our choice:** an icon-only button (`data-button="icon"`) is named by visually hidden text inside it, not `aria-label`, because real text is translated by browser translation tools and copied with the page. Its `<dui-tooltip>` shows the same words and is `aria-hidden`, so the name is announced once; with JavaScript off the button keeps its name.

### Size

`--dui-size-icon` (1.25rem) on its own; `--dui-size-icon-nav` (1rem) in nav links and summaries (`nav.css`); `--dui-size-icon-inline` (1rem) inside buttons, menu items, options and toolbars, so the icon matches the text beside it. Inside a button or link the flex gap spaces it from the label; in running text it sits on the middle of the line.

### Stroke

The CSS stroke-width property (`--dui-icon-stroke-width`, 1.75) overrides Lucide's stroke-width="2" presentation attribute, a lighter line at the smaller size.

### Direction

`data-icon="mirror"` flips the icon with :dir(rtl), which follows the nearest dir attribute, so a dir="ltr" island inside an RTL page stays unflipped. Never mirror search, close, play, check or logos.

## Accessibility

- Lucide draws with stroke="currentColor", so the icon takes the text color of whatever holds it, in every theme and in forced colors mode, where the browser forces color to a system color. An icon beside a visible label is decoration, hidden with aria-hidden="true" (WCAG 1.1.1); focusable="false" keeps old engines from putting the SVG in the tab order.
- An icon-only button gets its name on the button, not on the SVG (data-button="icon" in button.css).
- A standalone meaningful icon is role="img" with a \<title> instead. Copy the SVG from lucide.dev, replace its class attribute with data-icon, and add aria-hidden="true" focusable="false".

## Specifications

- [WCAG 1.1.1](https://www.w3.org/WAI/WCAG22/Understanding/non-text-content.html)
- [WCAG 1.4.11](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)
- [APG names and descriptions](https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/)
- [MDN `currentColor`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor)
- [MDN `forced-colors`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors)
- [lucide.dev](https://lucide.dev)
- [W3C svg](http://www.w3.org/2000/svg)
- [MDN `stroke-width`](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/stroke-width)
- [MDN `:dir`](https://developer.mozilla.org/en-US/docs/Web/CSS/:dir)

## See also

- [Atoms](https://domestic-ui.odonckers.dev/atoms/index.md)
- [Component API convention](https://domestic-ui.odonckers.dev/index.md#component-api)
- [Accessibility baseline](https://domestic-ui.odonckers.dev/principles/accessibility-baseline-wcag-22-aa.md)
- Source: [`css/components/atoms/icon.css`](https://github.com/odonckers/domestic-ui/blob/main/css/components/atoms/icon.css), [`examples/atoms/icon.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/atoms/icon.html)

## How other systems do it

For comparison only; these are not the standard this system follows.

- [Apple Human Interface Guidelines: Icons](https://developer.apple.com/design/human-interface-guidelines/icons)
- [Apple Human Interface Guidelines: SF Symbols](https://developer.apple.com/design/human-interface-guidelines/sf-symbols)
- [Material Design 3: Icons](https://m3.material.io/styles/icons/overview)
- Vercel Geist: No equivalent
