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
In the package npm i hellskitchen-ui Import hk-badge and use it directly.

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. Both follow count / showZero for visibility.
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 real text in the DOM, next to the content it is anchored to — give that content its own accessible name.
  • 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