Skip to content

Badge

A small inline pill for tags, counts, and status. Class + data-attribute API mirrors the Button: one .x-badge class plus data-variant, data-size, data-accent. No focus styles or pointer cursor β€” badges aren’t interactive.

Install

import "elements-kit/ui/styles/theme.css";
import "elements-kit/ui/styles/scaling.css";
import "elements-kit/ui/styles/radius.css";
import "elements-kit/ui/styles/space.css";
import "elements-kit/ui/styles/typography.css";
import "elements-kit/ui/styles/palette/gray.css";
import "elements-kit/ui/styles/neutral/gray.css";
import "elements-kit/ui/styles/palette/green.css";
import "elements-kit/ui/styles/accent/green.css";
import "elements-kit/ui/badge/badge.css";

unset.css is not required for <span>s β€” they have no native styling that bleeds through. Badges on a <button> or <a> should add unset to neutralise the native rendering first.

API

<span
class="x-badge"
data-variant="soft"
data-size="2"
data-accent="green"
>
New
</span>
AttributeValues
data-variantsolid, soft, surface, outline
data-size1, 2, 3
data-accentany imported color scale (green, blue, iris, …)
data-high-contrastmodifier β€” boosts contrast against the page background

Sizing

data-sizefont-sizepadding
1--font-size-1space-1/2 Γ— space-1.5
2--font-size-1space-1 Γ— space-2
3--font-size-2space-1 Γ— space-2.5

Border radius scales with data-radius on a parent β€” see Radius below.

Variants

  • solid β€” accent fill, high-contrast text. Counts and primary statuses.
  • soft β€” tinted background. Default for tags.
  • surface β€” outlined panel with subtle fill.
  • outline β€” bordered, transparent fill.

Radius

Set data-radius="<value>" on a parent to control corner radius for everything beneath. The badge follows the same radius-1..radius-6 scale as Button:

<div data-radius="pill">
<span class="x-badge" data-variant="soft">Pill</span>
</div>
<div data-radius="none">
<span class="x-badge" data-variant="soft">Square</span>
</div>

Available values: none, small, medium, large, pill. Each maps to a --radius-factor multiplier; pill additionally sets --radius-pill: 9999px for fully rounded pills.

Theming

Switch the color on a single badge with data-accent="<color>", or set it on any ancestor (e.g. <body>) to theme the whole subtree.

<span class="x-badge" data-variant="soft" data-accent="amber">
Beta
</span>

Light/dark flips automatically via the .dark class on a parent β€” see Light & dark.

Accessibility

.x-badge ships with no ARIA role β€” it’s a pure visual class. Add a role yourself based on what the badge means:

PatternMarkup
Decorative β€” text repeats surrounding context<span class="x-badge">New</span>
Status β€” info not present elsewhere<span class="x-badge" role="status">3 unread</span>
Live status β€” value can change at runtime<span class="x-badge" role="status" aria-live="polite">{count}</span>
Icon-only β€” no text inside the badge<span class="x-badge" role="img" aria-label="Online"></span>
Purely decorative dot β€” duplicates labeled text nearby<span class="x-badge" aria-hidden="true"></span>

Default to no role when the badge text already lives in the surrounding label β€” extra roles add noise to assistive tech. Reach for role="status" only when the badge contributes information a sighted reader would otherwise miss.