# Badge

Inline status labels with tone variants that meet WCAG AA contrast.

_Diagram: Badges label the status of each row in a table's Status column, such as Paid or Overdue._

## Live example

### Tones

```html
<p class="cluster">
  <span data-badge="primary">Pro</span>
  <span data-badge>Draft</span>
  <span data-badge="outline">Beta</span>
  <span data-badge="accent">New</span>
  <span data-badge="success">Paid</span>
  <span data-badge="warning">Due soon</span>
  <span data-badge="danger">Overdue</span>
</p>
```

### In context

```html
<section data-scroll="inline" aria-labelledby="invoices-caption" tabindex="0">
  <table>
    <caption id="invoices-caption">Invoices</caption>
    <thead>
      <tr><th scope="col">Invoice</th><th scope="col">Status</th></tr>
    </thead>
    <tbody>
      <tr><td>INV-031</td><td><span data-badge="success">Paid</span></td></tr>
      <tr><td>INV-032</td><td><span data-badge="danger">Overdue</span></td></tr>
    </tbody>
  </table>
</section>
```

## Attributes

`data-badge="neutral | accent | success | warning | danger"`

| Attribute or value | Effect |
| --- | --- |
| `data-badge="neutral \| primary \| outline \| accent \| success \| warning \| danger"` | (empty means neutral). primary is solid, outline is a bordered chip, and the tones are tinted, after shadcn/ui's badge variants (<https://ui.shadcn.com/docs/components/badge>). |

- Static text. To make a badge clickable, put a real `<button>` or `<a href>` around it.
- An empty value is neutral.

- **Our choice:** buttons, fields, selects and badges use the 14px interface size (`--dui-font-size-ui`). Fields, selects and text areas use `--dui-font-size-field`, which is at least 16px under a coarse pointer, because iOS Safari zooms into a focused field with smaller text.
- **Our choice:** badge tones are 8% of the tone mixed into the surface, with the tone as text. The tinted surfaces are derived tokens (`--dui-color-*-surface`), so a theme that changes the surface or a tone re-tints badges with no extra overrides.

## Accessibility

- The words carry the meaning, not the tone ([WCAG 1.4.1](https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html)). Add "Status:" with `.visually-hidden` if only position gives context.
- Text on each tone has 4.5:1 contrast ([WCAG 1.4.3](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html)), checked by `npm test`.

## Specifications

- [WCAG 1.4.3](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html)
- [WCAG 1.4.1](https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html)
- [Using ARIA rule 1](https://www.w3.org/TR/using-aria/#rule1)
- [ui.shadcn.com badge](https://ui.shadcn.com/docs/components/badge)

## 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/badge.css`](https://github.com/odonckers/domestic-ui/blob/main/css/components/atoms/badge.css), [`examples/atoms/badge.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/atoms/badge.html)

## How other systems do it

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

- Apple Human Interface Guidelines: No equivalent
- Material Design 3: No equivalent
- [Vercel Geist: Badge](https://vercel.com/geist/badge)
