Badge

stable 0.5 kB
<hk-badge>

A count or a dot, anchorable to any element. Counts past the cap collapse to "99+" so the badge never widens the layout underneath it.

#count#dot

Live demo

Running in this page — interact with it.

Inputs

NameTypeDefaultDescription
countnumber0Number shown. Zero hides the badge unless showZero.
maxnumber99Cap; anything above renders as "max+".
variant'count' | 'dot''count'Number or a bare dot.
showZerobooleanfalseKeeps the badge visible at zero.
tone'danger' | 'neutral' | 'success''danger'Colour.

Theming

Component tokens, each falling back to a global one:

PropertyDefaultControls
--hk-badge-bg#dc2626Badge fill.
--hk-badge-text#ffffffBadge text colour.
--hk-badge-ring#ffffffRing separating it from the content beneath.

Accessibility

  • The count is announced with its meaning through aria-label — "12 unread notifications", not a bare "12".
  • A dot badge is aria-hidden and relies on its host having a real accessible name.
  • Capping at max keeps the badge from resizing the control it is anchored to.

More in Data