Badge
Inline status labels with tone variants that meet WCAG AA contrast.
Live example
Tones
<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
<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). Add "Status:" with
.visually-hiddenif only position gives context. - Text on each tone has 4.5:1 contrast (WCAG 1.4.3), checked by
npm test.
Specifications
See also
- Atoms
- Component API convention
- Accessibility baseline
- Source:
css/components/atoms/badge.css,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