Install
Pull Badge from the barrel for everyday use, or the granular path when you want a tighter bundle.
import { Badge } from "@brika/clay";import { Badge } from "@brika/clay/components/badge";A minimal example
Drop this into a page. Native HTML attributes pass through to the underlying primitive.
import { Badge } from '@brika/clay/components/badge';
/** Default filled badge, use for status labels, counts, and tags. */
export default function BadgeDefaultDemo() {
return <Badge>New</Badge>;
}Badge, every way
Accessibility
- Renders as a
<span>, purely informational, carries no interactive role. - When used as a link with
asChild, the accessible name comes from the badge text. - Numeric count badges in tab triggers should be accompanied by a visually hidden description.
Theme tokens
Every CSS variable Badge reads, with its default and the
dotted path you'd write in a ThemeConfig JSON
to override it. Set any of these in your theme to retune Badge
without touching component code.
Badge tokens
31 tokens--badge-filled-containercolorvar(--primary)components.badge.filledContainerBackground of the default (filled) badge variant.
--badge-filled-labelcolorvar(--primary-foreground)components.badge.filledLabelLabel color of the default (filled) badge variant.
--badge-secondary-containercolorvar(--secondary)components.badge.secondaryContainerBackground of the secondary badge variant.
--badge-secondary-labelcolorvar(--secondary-foreground)components.badge.secondaryLabelLabel color of the secondary badge variant.
--badge-destructive-containercolorvar(--destructive)components.badge.destructiveContainerBackground of the destructive badge variant.
--badge-destructive-labelcoloroklch(1 0 0)components.badge.destructiveLabelLabel color of the destructive badge variant. Defaults to white so it stays legible regardless of `--destructive` hue.
--badge-outline-bordercolorvar(--border)components.badge.outlineBorderBorder color of the outline badge variant.
--badge-outline-labelcolorvar(--foreground)components.badge.outlineLabelLabel color of the outline badge variant.
--badge-ghost-hover-containercolorvar(--accent)components.badge.ghostHoverContainerHover background of the outline / ghost badge variants when wrapped in an `<a>` (`[a&]:hover`).
--badge-ghost-hover-labelcolorvar(--accent-foreground)components.badge.ghostHoverLabelHover label color of the outline / ghost badge variants when wrapped in an `<a>`.
--badge-link-colorcolorvar(--primary)components.badge.linkColorForeground color of the link badge variant.
--badge-focus-bordercolorvar(--ring)components.badge.focusBorderBorder color of the badge while focus-visible. Defaults to the `--ring` role so focus rings stay consistent with the rest of the system.
--badge-focus-ringcolorvar(--ring)components.badge.focusRingOuter focus halo of the badge, applied via `focus-visible:ring-badge-focus-ring/50`. Defaults to the `--ring` role at 50% so themes can recolor the badge focus halo without affecting other components.
--badge-invalid-bordercolorvar(--destructive)components.badge.invalidBorderBorder color when the badge carries `aria-invalid`. Defaults to the destructive role so themes can retune the validation tint independently.
--badge-invalid-ringcolorvar(--destructive)components.badge.invalidRingOuter ring color when the badge carries `aria-invalid`, applied at 20% (40% in dark mode) via `aria-invalid:ring-badge-invalid-ring/20`.
--badge-destructive-focuscolorvar(--destructive)components.badge.destructiveFocusFocus-ring color of the destructive badge variant. Applied via `focus-visible:ring-badge-destructive-focus/20` (and `dark:.../40`) so themes can shift the destructive halo independently of the fill.
--badge-radiusradiusvar(--radius-pill)components.badge.radiusBadge corner radius.
--badge-heightsize1.5remcomponents.badge.heightDefault badge height.
--badge-padding-xsizecalc(var(--spacing) * 2)components.badge.paddingXInline padding inside the badge.
--badge-padding-ysize0.125remcomponents.badge.paddingYBlock padding inside the badge.
--badge-gapsizecalc(var(--spacing) * 1)components.badge.gapGap between adjacent children inside the badge.
--badge-border-widthborder-width0pxcomponents.badge.borderWidthBorder width on the badge. Set non-zero for outline-style variants.
--badge-border-styleborder-stylesolidcomponents.badge.borderStyleBorder style on the badge (`solid`, `dashed`, `double`, `none`).
--badge-font-familyfont-familyvar(--font-sans)components.badge.fontFamilyTypeface for badge.
--badge-font-sizefont-sizevar(--text-label-md)components.badge.fontSizeFont size for badge.
--badge-font-weightfont-weight500components.badge.fontWeightFont weight for badge.
--badge-line-heightline-height1.25components.badge.lineHeightLine height for badge.
--badge-letter-spacingletter-spacing0components.badge.letterSpacingLetter spacing for badge. Useful for caps labels.
--badge-text-transformtext-transformnonecomponents.badge.textTransformText transform for badge (`uppercase`, `lowercase`, `capitalize`, `none`).
--badge-durationdurationvar(--motion-standard-duration)components.badge.durationTransition duration for badge state changes.
--badge-easingeasingvar(--motion-standard-easing)components.badge.easingTransition easing for badge state changes.
Override in a theme
Authoring a theme is plain JSON. Drop overrides under
components.badge, the names
are camelCase versions of the variable suffix.
{
"id": "my-theme",
"name": "My Theme",
"description": "...",
"accentSwatches": ["#000"],
"components": {
"badge": {
"paddingX": "calc(var(--spacing) * 2)"
}
}
}
Then apply with applyTheme(myTheme)
(see the theming guide),
scope it to a subtree with themeToCssVars(myTheme, mode),
or consume any token directly in your own JSX with the matching Tailwind utility
(e.g. bg-badge-…) — see the
chips on each token row.
API reference
Props specific to Badge. Native HTML attributes pass through to the underlying primitive, see the component source on GitHub for the full type signature.
- asChilddefault
falsebooleanWhen true, render the child element instead of the default DOM node and merge props. Lets you compose with<a>,<Link>, or another primitive while keeping behavior and styling. - variantdefault
'default''default' | 'secondary' | 'destructive' | 'outline' | 'ghost' | 'link'Visual treatment matching the Button variants (default, secondary, destructive, outline, etc.).