Skip to content

HyBadge

Usage examples on this page are written for Lit / plain HTML (<hy-badge>). The same component ships as HyBadge in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A versatile badge component for displaying status indicators, counts, and labels.

Key Features:

  • Multiple semantic variants (neutral, brand, success, warning, danger, info)
  • Optional dot indicator for status visualization
  • Number display for counts and notifications
  • Flexible sizing options
  • Accessible with proper ARIA attributes
  • CSS custom properties for extensive theming
  • Dot-only mode for status indicators without background

Accessibility Highlights:

  • Semantic color choices with sufficient contrast
  • Screen reader friendly content
  • Supports high contrast mode
  • Proper role attributes for status indicators

Examples

Basic usage - Default neutral badge

html
<hy-badge>LABEL</hy-badge>

Badge with status dot

html
<hy-badge variant="success" dot>LABEL</hy-badge>

Dot-only indicator (no background)

html
<hy-badge variant="success" dot></hy-badge>

Badge with number indicator

html
<hy-badge variant="danger" number="99">Notifications</hy-badge>

Number-only indicator (no background)

html
<hy-badge variant="danger" number="99"></hy-badge>

Different variants

html
<hy-badge variant="brand">LABEL</hy-badge>
<hy-badge variant="success">LABEL</hy-badge>
<hy-badge variant="warning">LABEL</hy-badge>
<hy-badge variant="danger">LABEL</hy-badge>

API

Properties

PropertyAttributeTypeDefaultDescription
variantvariant'neutral' | 'brand' | 'success' | 'warning' | 'danger' | 'info''neutral'Visual style variant determining the badge's color scheme and semantic meaning.
emphasisemphasis'solid' | 'soft' | 'outlined' | 'tinted''solid'Visual chrome weight on top of the role.
sizesize'small' | 'medium' | 'large''medium'Physical size of the badge affecting dimensions, padding, and typography scale.
dotdotbooleanfalseDisplays a colored dot indicator before the badge content.
pendingpendingbooleanfalseMarks the badge as in-progress / processing: shows the status dot (even if dot is not set) and gives it a gentle pulse, plus aria-busy on the status region. The idiomatic "processing" indicator (cf. Ant Badge status="processing") — pair with any variant (e.g. warning for a running task). The pulse honors prefers-reduced-motion and is driven by the loop.pulse motion token (overridable via --hy-badge-pulse-*).
numbernumbernumber | undefinedundefinedDisplays a numeric indicator after the badge content.
countLabelcount-labelstring | undefinedAccessible label for the badge count. Use for internationalization. Overrides the default "${n} items" pattern.
categoryGroupcategory-groupstring | undefinedCategorical group name to hash into. Only applied when variant is neutral; a non-neutral variant wins. Selects which palette in the active DS's roles.categorical map this badge pulls from.
identityidentitystring | undefinedIdentity string hashed to a stable slot within categoryGroup — same identity always produces the same color. Ignored when slotIndex is set.
slotIndexslot-indexnumber | undefinedExplicit 1-indexed slot within categoryGroup. Takes precedence over identity. Out-of-range values fall back to default styling.

Slots

SlotDescription
defaultPrimary badge content (text, inline elements). Usage: Main badge label; can contain text nodes and inline elements. Accessibility: Content contributes to accessible name calculation.

CSS Parts

PartDescription
baseThe root badge element. Usage: Primary styling target for customizing the badge's appearance.
dotThe dot indicator element (when dot=true). Usage: Styling target for the status dot.
numberThe number indicator element (when number is set). Usage: Styling target for the number badge.

CSS Custom Properties

PropertyDescription
--hy-badge-text-transformText transform for badge label Default: none
--hy-badge-font-familyFont family override for badge label Default: var(--hy-label-xs-font-family)
--hy-badge-spacingGap between badge content parts (icon, text) Default: var(--hy-gap-pill-md-inline)
--hy-badge-radiusBadge corner radius Default: var(--hy-radius-pill-md) (pill)
--hy-badge-padding-xInline padding at medium size Default: var(--hy-padding-pill-md-inline)
--hy-badge-padding-yBlock padding at medium size Default: var(--hy-padding-pill-md-block)
--hy-badge-padding-size-smBlock padding at small size Default: var(--hy-padding-pill-sm-block)
--hy-badge-padding-size-sm-inlineInline padding at small size Default: var(--hy-padding-pill-sm-inline)
--hy-badge-padding-size-lg-blockBlock padding at large size Default: var(--hy-padding-pill-lg-block)
--hy-badge-padding-size-lg-inlineInline padding at large size Default: var(--hy-padding-pill-lg-inline)
--hy-badge-dot-padding-xInline padding in dot-only mode Default: var(--hy-padding-layout-2xs)
--hy-badge-dot-padding-yBlock padding in dot-only mode Default: var(--hy-padding-layout-none)
--hy-badge-dot-radiusDot corner radius Default: var(--hy-radius-pill-md) (pill)
--hy-badge-number-radiusNumber indicator corner radius Default: var(--hy-radius-pill-md) (pill)
--hy-badge-number-sizeSize of the number indicator
--hy-badge-number-paddingHorizontal padding of the number indicator
--hy-badge-dot-size-smDot size at small / dot-only mode Default: var(--hy-indicator-size-2xs)
--hy-badge-dot-size-mdDot size at medium Default: var(--hy-indicator-size-xs)
--hy-badge-dot-size-lgDot size at large Default: var(--hy-indicator-size-sm)
--hy-badge-pulse-durationDuration of the pending dot pulse Default: var(--hy-motion-loop-pulse-duration)
--hy-badge-pulse-easingEasing of the pending dot pulse Default: var(--hy-motion-loop-pulse-easing)

Built with Lit. Documented with VitePress.