ELFBAR

Badge

Status indicator or count label attached to a host element's top-right corner, available in Dot and Count forms.

A Badge attaches to the top-right corner of host elements like icons or avatars, conveying either "new content available" or "a specific count." The Dot type shows only a circle, indicating presence/absence; the Count type shows a number, collapsing to 99+ when maxCount is exceeded.

Anatomy

┌─ Host Element ────────────┐
│            ┌─Count─┐      │
│            │  99+  │      │  ← background + number
│            └───────┘      │
└───────────────────────────┘
  1. Container — Rounded background (Count: --ds-radius-sm; Dot: 8×8px circle)
  2. Content — Count type shows a number; Dot type is an empty circle
  3. Anchor — Badge is absolutely positioned at the position: relative container's top-right corner

Usage Guidelines

✅ Do

  • Use Dot for presence/absence cues (e.g. new notifications), not for conveying specific quantities
  • Use Count for specific counts like "N unread", with an appropriate maxCount (default 99)
  • Place the badge at the top-right corner of the host element, avoiding obscuring critical content
  • Hide the badge when count is 0 by default (showZero: false) to avoid visual noise

❌ Don't

  • Don't place multiple badges on the same host element — visually confusing and imprecise
  • Don't use badges purely for decoration — they carry semantic meaning and overuse dilutes that
  • Don't display excessively large numbers in Count type (must collapse beyond maxCount)
  • Don't apply badges to non-icon/avatar host elements (body text, button labels, etc.)

Interaction Behavior

StateBehavior
Static displayShown alongside the host element; does not receive independent pointer events
Count updateRecommend a scale animation on number change for visual feedback
AppearScale from 0 to 1, duration ≈ 200ms
DisappearReverse scale to 0, duration ≈ 200ms
Collapsecount > maxCount shows {maxCount}+, no longer increases

Accessibility

RequirementImplementation
Semantic labelHost element or badge itself uses aria-label="3 unread messages"
Dot typearia-label="New notifications" indicating presence/absence
Live updatesWrap with aria-live="polite" to announce count changes
ContrastBadge background-to-host/page contrast ≥ 3:1
Pointer eventsBadge has pointer-events: none to not interfere with host interactions