Skip to content

Badge

A small label for a status, a count or a category. Same markup and props in every style: switch the style in the header to see it change.

Variants

Neutral for plain labels, primary to draw the eye, and the status colours for success, warning and danger.

Draft New Active Pending Failed v0.1.0
badge-variants.html
<span class="vin-badge">Draft</span>
<span class="vin-badge vin-badge--primary">New</span>
<span class="vin-badge vin-badge--success">Active</span>
<span class="vin-badge vin-badge--warning">Pending</span>
<span class="vin-badge vin-badge--danger">Failed</span>
<span class="vin-badge vin-badge--outline">v0.1.0</span>

With a status dot

Add a dot for live status. The dot follows the badge's text colour.

Online Degraded Offline Paused
badge-dot.html
<span class="vin-badge vin-badge--success"><span class="vin-badge__dot" aria-hidden="true"></span>Online</span>
<span class="vin-badge vin-badge--warning"><span class="vin-badge__dot" aria-hidden="true"></span>Degraded</span>
<span class="vin-badge vin-badge--danger"><span class="vin-badge__dot" aria-hidden="true"></span>Offline</span>
<span class="vin-badge"><span class="vin-badge__dot" aria-hidden="true"></span>Paused</span>

In context

Badges sit inside buttons and next to headings without extra CSS.

badge-in-context.html
<button type="button" class="vin-btn vin-btn--secondary">
  Inbox
  <span class="vin-badge vin-badge--primary">12</span>
</button>
<button type="button" class="vin-btn vin-btn--outline">
  Releases
  <span class="vin-badge vin-badge--success">New</span>
</button>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add badge
React
import { Badge, badgeClasses } from "@/components/vin/badge";
Vue
import Badge, { badgeClasses } from "@/components/vin/badge.vue";
Svelte
import Badge, { badgeClasses } from "$lib/components/vin/badge.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.

API

From spec/badge.json, which every framework version is tested against.

PropValuesDefaultIn HTML
variantneutralprimarysuccesswarningdangeroutlineneutralvin-badge--{value}
dotbooleanfalse<span class="vin-badge__dot" aria-hidden="true"></span> as the first child

Parts

React, Vue, SvelteHTML classes
<Badge>.vin-badge.vin-badge--primary.vin-badge--success.vin-badge--warning.vin-badge--danger.vin-badge--outline.vin-badge__dot

Accessibility

  • Badges are plain text, so screen readers read them as they are.
  • Never rely on colour alone: the label says the status ("Failed", not just a red badge).
  • The status dot is decorative and hidden from screen readers.
  • Text meets 4.5:1 contrast in every style and mode.