Skip to main content

Badge

Info:Display html svelte astro Success: coverage 103/103

A compact status or label chip: three fills across six semantic tones and twelve named hues.

Live demo

live · @xoji/astro

Badge

Three fills, six semantic tones

solid

accent neutral Success:success Warning:warn Danger:danger Info:info

soft

accent neutral Success:success Warning:warn Danger:danger Info:info

outline

accent neutral Success:success Warning:warn Danger:danger Info:info

Every tone

Accents

accent accent-2 accent-3 accent-4 neutral

Statuses

Success:success Info:info Warning:warn Danger:danger

Named hues

red orange yellow green blue purple brown pink cyan gray white black

Sizes, dots, counts, and dismissal

small medium large
Success:Live Warning:Degraded Danger:Offline Info:Inbox12 Alerts99+
design frontend tokens

Badge labels, counts, and statuses inline. Fill treatment (variant) and color (tone) are independent axes: each of the three fills (solid, soft, outline) can carry any of the six semantic tones (accent, neutral, danger, success, warn, info) or any of the twelve named hues (red … black).

It adds a leading status dot, a tabular count affordance, and a dismissible form whose × is a real focusable <button>. A standalone .xoji-dot indicator covers the bare-dot case. Status tones (success, warn, danger, info) emit a screen-reader-only tone word so meaning never rides on color alone.

When to use

How this component composes with the rest of the set.

Pair with a list or tag input as removable chips; wire onremove (svelte) or the .xoji-badge__remove click (html/astro) to drop the item.
Use the standalone .xoji-dot indicator next to avatars or rows for presence without a full chip.
The count affordance pairs with nav items and tabs for unread counts.

Props

8 props, straight from the manifest.

PropTypeDefaultBindingsDescription
variant BadgeVariant
solid soft outline
soft
html svelte astro
Fill treatment. Independent of tone.
tone FullTone
accent neutral danger success warn info accent-2 accent-3 accent-4 red orange yellow green blue purple brown pink cyan gray white black
neutral
html svelte astro
Any color tone — a semantic role, an accent variant (accent-2/3/4), or a named hue (red … black).
size Size
sm md lg
md
html svelte astro
Chip size; the scale tops out smaller than the controls (no `xl`).
dot boolean false
html svelte astro
Shows a leading status dot in the current text color.
count string | number
html svelte astro
A numeric count rendered after the label in tabular figures.
removable boolean false
html svelte astro
Adds a dismiss `×` button. html/svelte wire it to fire `onremove`; Astro emits static markup you wire yourself.
removeLabel string Remove
html svelte astro
Accessible name for the dismiss button (kebab `remove-label` on the custom element).
onremove (event: MouseEvent) => void
svelte
Handler invoked when the dismiss button is activated.

Appearance

Variants

solid

.xoji-badge--solid

Filled with the tone color. The highest-emphasis treatment.

soft

.xoji-badge--soft

A soft tone-tinted background with tone-colored text. The default.

outline

.xoji-badge--outline

Transparent fill with a tone-colored border and text.

Sizes

sm

.xoji-badge--sm

Compact.

md

default
.xoji-badge

Default.

lg

.xoji-badge--lg

Large.

States

remove-hover

.xoji-badge__remove:hover::after

Pointer over the dismiss button. Its overlay paints the hover tint.

remove-active

.xoji-badge__remove:active::after

Dismiss button pressed. Its overlay paints the press tint.

remove-focus-visible

.xoji-badge__remove:focus-visible

Keyboard focus on the dismiss button: a token ring plus a transparent outline that becomes real in forced-colors mode.

Anatomy

The named parts that make up the component, with their selectors.

badge

.xoji-badge

The chip root carrying the variant, tone, and size classes.

--font-sans --text-xs --weight-medium --leading-tight --neutral-bg --neutral-text --border-thin --radius-full --space-0 --space-2

dot

.xoji-badge__dot

The optional leading status dot, painted in the badge's current text color.

--space-2 --space-3 --radius-full

label

.xoji-badge__label

The text content wrapper.

count

.xoji-badge__count

A tabular-numeric count affordance rendered after the label.

--weight-semibold

remove

.xoji-badge__remove

A real <button> dismiss control with an accessible name, its own focus ring, and a state overlay.

--space-1 --radius-full --duration-fast --ease-standard --state-hover --state-press --border-normal --border-thick --ring

indicator

.xoji-dot

A standalone dot indicator independent of any chip, tonable and sizable on its own.

--space-1 --space-2 --space-3 --radius-full --neutral

Tokens & coverage

What the component consumes, checked live against what the algorithm produces.

Success:fully covered 103/103 consumed tokens produced default register: 276 tokens

Live coverage check against the xoji-default register (derive(xojiDefault, { anchors })coverComponent(manifest, register)). Every token this component consumes must be a key the algorithm produces.

--accent --accent-2 --accent-2-bg --accent-2-fg --accent-2-text --accent-3 --accent-3-bg --accent-3-fg --accent-3-text --accent-4 --accent-4-bg --accent-4-fg --accent-4-text --accent-bg --accent-fg --accent-text --black --black-bg --black-fg --black-text --blue --blue-bg --blue-fg --blue-text --border-normal --border-thick --border-thin --brown --brown-bg --brown-fg --brown-text --cyan --cyan-bg --cyan-fg --cyan-text --danger --danger-bg --danger-fg --danger-text --duration-fast --ease-standard --font-sans --gray --gray-bg --gray-fg --gray-text --green --green-bg --green-fg --green-text --info --info-bg --info-fg --info-text --leading-tight --neutral --neutral-bg --neutral-fg --neutral-text --orange --orange-bg --orange-fg --orange-text --pink --pink-bg --pink-fg --pink-text --purple --purple-bg --purple-fg --purple-text --radius-full --red --red-bg --red-fg --red-text --ring --space-0 --space-1 --space-2 --space-3 --state-hover --state-press --success --success-bg --success-fg --success-text --text-sm --text-xs --warn --warn-bg --warn-fg --warn-text --weight-medium --weight-semibold --white --white-bg --white-fg --white-text --yellow --yellow-bg --yellow-fg --yellow-text

Slots

default
html svelte astro

The badge label.

Accessibility

Status tones (success, warn, danger, info) emit a screen-reader-only tone word, so meaning is conveyed without relying on color (WCAG 1.4.1).
The leading dot is decorative (aria-hidden); the standalone .xoji-dot should carry role="img" and an aria-label when it conveys meaning on its own.
The dismiss control is a native <button> with an aria-label; the html/svelte bindings warn at runtime when you omit remove-label.
The dismiss button shows focus with a token ring plus a transparent outline that the forced-colors base rule promotes to a real system outline.
The × glyph is drawn as a decorative aria-hidden SVG; the button's accessible name comes from its label, not the icon.

Code

Fills, tones, and affordances

The three fills cross all tones and hues; dot, count, and the removable form layer on top, with a standalone dot for the bare case.

<xoji-badge variant="soft" tone="accent">New</xoji-badge>

<xoji-badge variant="solid" tone="success" dot>Online</xoji-badge>

<xoji-badge variant="outline" tone="danger">Failed</xoji-badge>

<xoji-badge tone="info" count="12">Notifications</xoji-badge>

<xoji-badge variant="soft" tone="purple" removable remove-label="Remove tag">design</xoji-badge>

<span class="xoji-dot xoji-dot--success" role="img" aria-label="Online"></span>
<script lang="ts">
	import { Badge } from "@xoji/svelte";
</script>

<Badge variant="soft" tone="accent">New</Badge>

<Badge variant="solid" tone="success" dot>Online</Badge>

<Badge variant="outline" tone="danger">Failed</Badge>

<Badge tone="info" count={12}>Notifications</Badge>

<Badge variant="soft" tone="purple" removable removeLabel="Remove tag" onremove={() => drop("design")}>design</Badge>
---
import { Badge } from "@xoji/astro";
---

<Badge variant="soft" tone="accent">New</Badge>

<Badge variant="solid" tone="success" dot>Online</Badge>

<Badge variant="outline" tone="danger">Failed</Badge>

<Badge tone="info" count={12}>Notifications</Badge>

<Badge variant="soft" tone="purple" removable removeLabel="Remove tag">design</Badge>

<span class="xoji-dot xoji-dot--success" role="img" aria-label="Online"></span>