Data display
Badge
Free1.8 KB gzippedA small, non-interactive status or label pill. Use it for statuses ("Final", "Live"), categories, and counts. Always give it text or an icon plus text, so its meaning never depends on color alone.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · No keyboard interaction of its own · Full report
Import
import { Badge, BadgeAnchor } from "@vjdesigns/vjdesigns-ui";
Importing only Badge adds about 1.8 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Variants and tones
import { Badge, Flex, Stack } from "@vjdesigns/vjdesigns-ui";
export function VariantsAndTones() {
const tones = ["neutral", "primary", "accent", "success", "warning", "danger", "info"] as const;
return (
<Stack gap={3} align="center">
{(["soft", "solid", "outline"] as const).map((variant) => (
<Flex key={variant} gap={2} wrap="wrap" justify="center">
{tones.map((tone) => (
<Badge key={tone} variant={variant} tone={tone}>
{tone}
</Badge>
))}
</Flex>
))}
</Stack>
);
}
Inverse
inverse swaps the solid colors, for a badge on a solid tone surface such as a solid Navbar, a Banner or a primary card. It uses the same verified color pair as solid, so it keeps its contrast in both themes.
import { Badge, Flex } from "@vjdesigns/vjdesigns-ui";
export function Inverse() {
const tones = ["neutral", "primary", "accent", "success", "warning", "danger", "info"] as const;
return (
<Flex gap={2} wrap="wrap" justify="center">
{tones.map((tone) => (
<div
key={tone}
style={{
display: "flex",
gap: "var(--space-2)",
alignItems: "center",
padding: "var(--space-2) var(--space-3)",
borderRadius: "var(--radius-lg)",
background: `var(--color-${tone})`,
color: `var(--color-on-${tone})`,
}}
>
{tone}
<Badge variant="inverse" tone={tone} count={3} label={`3 ${tone} items`} />
</div>
))}
</Flex>
);
}
Status and counts
dot marks a status; count shows a number capped at max.
import { Badge, Flex } from "@vjdesigns/vjdesigns-ui";
export function StatusAndCounts() {
return (
<Flex gap={3} wrap="wrap" justify="center" align="center">
<Badge dot tone="success">
Active
</Badge>
<Badge dot tone="warning">
Pending
</Badge>
<Badge tone="primary" variant="solid" count={8} label="8 new messages" />
<Badge tone="danger" variant="solid" count={240} max={99} label="240 alerts" />
<Badge caps tone="accent" variant="solid">
New
</Badge>
</Flex>
);
}
Anchored
BadgeAnchor pins a badge to the corner of another element, like a notification count on an icon button.
import {
BadgeAnchor,
BellIcon,
Flex,
IconButton,
MailIcon,
} from "@vjdesigns/vjdesigns-ui";
export function Anchored() {
return (
<Flex gap={6} align="center">
<BadgeAnchor count={3} label="3 unread notifications">
<IconButton aria-label="Notifications" variant="soft" tone="neutral">
<BellIcon />
</IconButton>
</BadgeAnchor>
<BadgeAnchor dot tone="danger" label="New mail">
<IconButton aria-label="Inbox" variant="soft" tone="neutral">
<MailIcon />
</IconButton>
</BadgeAnchor>
</Flex>
);
}
Accessibility
A bare "3" means nothing to a screen reader: label gives the badge spoken text ("3 unread messages") and hides the visible number from assistive technology. A dot is decorative, so always pair it with words.
import {
BadgeAnchor,
Badge,
Flex,
IconButton,
MailIcon,
} from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<Flex gap={6} align="center" wrap="wrap">
<BadgeAnchor count={3} label="3 unread messages">
<IconButton aria-label="Messages" variant="ghost" tone="neutral">
<MailIcon />
</IconButton>
</BadgeAnchor>
<Badge tone="danger" variant="soft" dot>
Payment failed
</Badge>
</Flex>
);
}
Translated
Badge text and labels are your own, so translate the label along with the visible text. LocaleProvider sets lang, so the label is read in Japanese.
import {
BadgeAnchor,
Badge,
BellIcon,
Flex,
IconButton,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import ja from "@vjdesigns/vjdesigns-ui/locales/ja";
export function Translated() {
return (
<LocaleProvider locale="ja" messages={ja}>
<Flex gap={6} align="center">
<BadgeAnchor count={120} max={99} label="未読の通知 120 件">
<IconButton aria-label="通知" variant="ghost" tone="neutral">
<BellIcon />
</IconButton>
</BadgeAnchor>
<Badge tone="success" variant="soft" dot>
公開中
</Badge>
</Flex>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Variants and tones
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// VariantsAndTones is the "Variants and tones" example above.
<LocaleProvider locale="ar" messages={ar}>
<VariantsAndTones />
</LocaleProvider>
Usage notes
Renders a <span> with no role. For counts, pass label (e.g. "3 unread messages") so screen readers hear more than a bare number.
API reference
Badge
| Prop | Type | Default |
|---|---|---|
radiusCorner rounding. | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
startIconDecorative icon before the text. Hidden from assistive technology, so the text must carry the meaning. | ReactNode | — |
dotShows a small leading status dot in the current text color. Decorative: pair it with text. | boolean | false |
capsUppercase display type with wide tracking and heavy weight: the athletic "jersey" look. | boolean | false |
childrenThe badge text. Ignored when | ReactNode | — |
variantVisual style. | "solid""soft""outline""inverse" | "solid" on `BadgeAnchor`, "soft" on `Badge` |
toneSemantic color. | "neutral""primary""accent""success""warning""danger""info" | "neutral" on `Badge`, "accent" on `BadgeAnchor` |
sizeHeight, padding, and type size. | "sm""md""lg" | "md" |
countA number to show instead of | number | — |
maxLargest count shown before it collapses to | number | 99 |
showZeroShow the badge when | boolean | false |
labelAccessible text that replaces the visible content for screen readers, e.g. | string | — |
Also accepts native <span> attributes, plus className, style and ref.
BadgeAnchor
Pins a count, dot, or short label to a corner of its child. The badge is ringed in --color-bg (override with the --badge-ring-color custom property on a colored surface) so it reads as separate from the anchor.
Accessibility: the badge is decorative by default (aria-hidden) because an interactive anchor should carry the information in its own name, e.g. <IconButton aria-label="Notifications, 3 unread">. For a non-interactive anchor (like an avatar), pass label to add screen-reader text instead. To announce count changes, use one app-level live region, not a live region on every badge.
| Prop | Type | Default |
|---|---|---|
childrenRequiredThe element the badge is attached to, such as an | ReactNode | — |
dotShow a small dot instead of a count or | boolean | false |
contentCustom badge content (a short text or icon) when not using | ReactNode | — |
placementCorner of the anchor to sit on. Logical, so | "top-end""top-start""bottom-end""bottom-start" | "top-end" |
overlapShape of the anchor, so the badge sits on its visible edge. | "rectangle""circle" | "rectangle" |
offsetNudges the badge from its corner. A single value moves it that far outward on both axes (negative moves inward); a tuple sets | BadgeOffsetValue | [inline: BadgeOffsetValue, block: BadgeOffsetValue] | — |
invisibleHide the badge with a springy scale-out. The badge stays mounted so it can animate back in. | boolean | false |
badgeClassNameExtra class for the badge itself (the root class goes on the wrapper). | string | — |
variantVisual style. | "solid""soft""outline""inverse" | "solid" on `BadgeAnchor`, "soft" on `Badge` |
toneSemantic color. | "neutral""primary""accent""success""warning""danger""info" | "neutral" on `Badge`, "accent" on `BadgeAnchor` |
sizeHeight, padding, and type size. | "sm""md""lg" | "md" |
countA number to show instead of | number | — |
maxLargest count shown before it collapses to | number | 99 |
showZeroShow the badge when | boolean | false |
labelAccessible text that replaces the visible content for screen readers, e.g. | string | — |
Also accepts native <span> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Badge targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
Not focusable, so there's no keyboard interaction of its own.
Roles and states
| Element | Role | States and properties |
|---|---|---|
<span> | none (generic) | Read as text; give it words, not only a color |
BadgeAnchor count | none | aria-label on the anchor ("3 unread") |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |