Skip to content
Focsd homeFocsd homeFocsd
Forms

Badge

A short status label.

  • Tag: focsd-badge
  • Pattern: Static
  • Category: Display

Example

Draft Active Expiring Overdue Beta
HTML
<focsd-badge>Draft</focsd-badge>
<focsd-badge tone="positive">Active</focsd-badge>
<focsd-badge tone="caution">Expiring</focsd-badge>
<focsd-badge tone="critical">Overdue</focsd-badge>
<focsd-badge tone="info">Beta</focsd-badge>

Indicator

A dot or a count on the corner of an avatar or icon, such as unread messages or who is online.

Inbox Messages
HTML
<a href="#inbox"
>Inbox<focsd-badge count="3" label="unread"
><focsd-icon name="info"></focsd-icon></focsd-badge
></a>
<focsd-button
><focsd-badge count="120" label="unread"
><focsd-icon name="menu"></focsd-icon></focsd-badge
>Messages</focsd-button
>
<focsd-badge dot label="Online"
><focsd-avatar name="Ada Lovelace"></focsd-avatar
></focsd-badge>
<focsd-badge dot label="Away" placement="bottom-end"
><focsd-avatar name="Grace Hopper"></focsd-avatar
></focsd-badge>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-badge.js';
</script>
<focsd-badge>Draft</focsd-badge>

API

Attributes

AttributePropertyTypeDefault
tonetone'neutral' | 'info' | 'positive' | 'caution' | 'critical'neutral
dotdotbooleanfalse
countcountnumber | undefined—
maxmaxnumber99
placementplacementBadgePlacementtop-end
labellabelstring—
colorcolorstring—

Slots

SlotDescription
(default)Default content: the label, or the anchor with dot or count.

CSS parts

Style the inside of the component with ::part(), for example focsd-badge::part(badge).

PartDescription
badgeThe inline badge (without `dot` or `count`).
anchorThe wrapper around the anchor (with `dot` or `count`).
indicatorThe dot or the count at the anchor's corner; hidden from assistive technology.
hidden-textVisually hidden text that names the indicator.

Accessibility

  • Plain inline text: the words carry the meaning, the tone color only reinforces it.

Indicator

  • With dot or count, the default slot is the anchor (an avatar or icon) and the badge draws an indicator on one of its corners.
  • The indicator is hidden from screen readers. Visually hidden text says the same thing: the count and the label ("3 unread"), or the dot’s label ("Online"). Inside a link or button it becomes part of the name, with a space on each side, such as "Inbox 3 unread" or "120 unread Messages".
  • The visible count stops at max (99 by default, shown as "99+"); the hidden text keeps the real number.
  • A count of 0 shows the anchor alone and adds nothing to the name.
  • A dot needs a label; without one it is decorative, adds nothing to the name, and the badge warns once in the console, because a colored dot means nothing to a screen reader.
  • placement picks the corner: top-end (the default), top-start, bottom-end or bottom-start. Start and end follow the reading direction, so top-end is top left in right-to-left text.
  • The count is dark text on a light red tint with a red edge; the dot is solid red with a ring in the surface color. Both stay visible in forced colors.