Skip to the content
human-kit design
50 — Data display

Badge

A short label in a colour: a state, a category, a count.

To approve

Installation

pnpm dlx @human-kit/design add badge
npx @human-kit/design add badge
yarn dlx @human-kit/design add badge
bunx @human-kit/design add badge

The command copies the files to src/lib/components/ui/badge. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as Badge from '$lib/components/ui/badge';
</script>

<Badge.Root tone="green">Approved</Badge.Root>

Examples

Tones

Ten tones, with no meaning of their own: one app’s "Pending" is orange, another’s amber. Map each state to a tone once, in the app, and every badge of that state follows. Blue when none is given, gray for a label that should stay quiet. badgeTones lists them.

gray blue cyan teal green amber orange red pink violet

Sizes

Three sizes, 16, 19 and 22px tall: the type, the padding and the dot step together, in every look.

Approved Approved Approved Approved Approved Approved Approved Approved Approved

Guidelines

  • Use a badge for a short state or a tag, one or two words, never for an action: it does not press.
  • Use default, the tone as a muted tint with no edge, where a badge stands alone or in a few rows. Its hue is the avatar’s, so a badge and an avatar of one tone read as one family.
  • Use outline in a column where many badges sit together: the words in ink and the tone in a dot are calmer than a column of tinted chips. Without the dot it is a plain label.
  • Use text, the dot and the words with no chip, inside something that already is a box, such as a card’s header.
  • Use sm where the room is tight, in a dense table, and lg beside a heading or in a roomy card. Each size steps the type, the padding and the height: 16, 19 and 22px.

Accessibility

  • It renders a <span> with no role: its words are read as part of the text around it.
  • The dot is hidden from screen readers. The words say the state, so the colour is never the only sign.
  • Each tone’s words are checked at 4.5:1 or more against its tint, the contrast of body text: 6.8:1 or more in light and dark.
  • When the badge alone says something the row does not, such as a count, give the row an aria-label that says it whole.

API reference

PropTypeDefault
variant'default' | 'outline' | 'text'

A muted tint of the tone, a white chip with a dot, or the dot and the words alone.

'default'
tone'gray' | 'blue' | 'cyan' | 'teal' | 'green' | 'amber' | 'orange' | 'red' | 'pink' | 'violet'

The colour. Its meaning is the app’s to give. gray for a label that should stay quiet.

'blue'
size'sm' | 'default' | 'lg'

The type, the padding and the height: 16, 19 or 22px.

'default'
dotboolean

The tone’s dot before the words. text always has it.

true

Plus every attribute of a <span>.