Skip to main content

Core · Show content

Tag and badge

Labels an item with a short status or category (tag), or shows a count (badge).

Example

Seven tag colours and three badges with a count.

Gray Blue Green Red Yellow Teal Purple
3 12 99+

Known issues

None known.

Code

Copy the markup

HTML
<span class="luz-tag luz-tag--green luz-tag--dot">Running</span>
HTML
<a href="/inbox/">Inbox <span class="luz-badge luz-badge--primary">3</span><span class="u-sr-only"> unread</span></a>

Variants and options

A tag takes one colour and, if you like, the dot. A badge takes one colour.

ClassEffect
.luz-tag--gray
Neutral: a category with no status
.luz-tag--blue
Information colours
.luz-tag--green
Success colours
.luz-tag--yellow
Warning colours
.luz-tag--red
Danger colours
.luz-tag--teal, .luz-tag--purple
Extra colours for categories, with no status meaning
.luz-tag--dot
A small dot before the text, a second cue besides colour
.luz-badge--primary
Brand fill
.luz-badge--gray
Neutral fill
.luz-badge--danger
Danger fill

How it works

Inline <span> elements, styled by components/tag.css. No JavaScript.

  • A tag is at least 24 px high, in extra-small text, on a tint of its colour.
  • A badge is a small rounded count in the mono font, at least 20 px wide.

Without JavaScript

Nothing changes: tags and badges are HTML and CSS.

Keyboard and ARIA

Tags and badges are not interactive and take no focus.

  • The text carries the meaning; the colour adds nothing a screen reader needs.
  • A count needs context: put the badge inside the link or heading it counts, and add the unit as visually hidden text if it is not on screen ("3 unread").

Contrast and focus are in the Design tab.

Design

When to use

Use a tag to label an item with a short status or category, and a badge to show a count next to a link or a heading.

When not to use

Do not use a tag for an action: it is not clickable.

  • For an action, use a button.
  • For a sentence, use an alert.
  • Do not give teal or purple a status meaning: they are for categories.

Do and don't

Do Status colours for status: green running, yellow degraded, red stopped, each with its word.
Don't Teal and purple as statuses: they are for categories, so the reader cannot guess that teal means running.

Writing the content

One or two words, in sentence case: "Running", "Degraded".

  • Never only a colour name: the reader may not see the colour.
  • Badges hold numbers; cap them ("99+") so they keep their size.

Contrast and focus

Each tag puts its text colour on its own tint; badges put white text on a fill.

PartColour on backgroundLightDarkHigh contrastNeeds
Gray tag
--luz-text-secondary on --luz-surface-strong
5.3:1
5.4:1
16.5:1
4.5:1
Blue tag
--luz-color-info on --luz-color-info-bg over --luz-surface-page
9.0:1
9.7:1
13.6:1
4.5:1
Green tag
--luz-color-success on --luz-color-success-bg over --luz-surface-page
5.4:1
10.1:1
8.9:1
4.5:1
Red tag
--luz-color-danger on --luz-color-danger-bg over --luz-surface-page
5.4:1
10.2:1
8.9:1
4.5:1
Yellow tag
--luz-color-warning on --luz-color-warning-bg over --luz-surface-page
6.8:1
9.0:1
8.9:1
4.5:1
Teal tag
--luz-color-teal on --luz-color-teal-bg over --luz-surface-page
5.4:1
7.1:1
8.9:1
4.5:1
Purple tag
--luz-color-purple on --luz-color-purple-bg over --luz-surface-page
5.4:1
12.2:1
9.0:1
4.5:1
Primary badge
--luz-text-on-fill on --luz-brand-fill
6.0:1
4.9:1
14.1:1
4.5:1
Gray badge
--luz-text-on-fill on --luz-outline
4.6:1
4.8:1
21.0:1
4.5:1
Danger badge
--luz-text-on-fill on --luz-color-danger-fill
5.6:1
6.0:1
9.3:1
4.5:1

Measured from the token values of each mode, rounded down. Needs is the WCAG 2.2 AA minimum: 4.5:1 for text, 3:1 for focus rings, borders and icons.

  • Focus: tags and badges take none: they are not controls.
  • Not colour alone: the word carries the status; .luz-tag--dot adds a shape for the status tags.

Tokens it uses

The 24 tokens that components/tag.css reads, by family. Each family links to its page, with the values in every mode. In Figma they are variables with the same names: see Tokens in Figma.

Spacing and sizing
--luz-space-2xs, --luz-space-xs
Typography
--luz-font-mono, --luz-text-xs
Radius
--luz-radius-full, --luz-radius-sm

Keyboard and ARIA are in the Code tab.