Badge
A short status label.
Example
<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.
<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>import { Badge } from '@focsd-dev/react';
export function Example() { return <Badge>Draft</Badge>;}<script setup>import '@focsd-dev/components/focsd-badge.js';</script>
<template> <focsd-badge>Draft</focsd-badge></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-badge.js';
// template<focsd-badge>Draft</focsd-badge><script> import '@focsd-dev/components/focsd-badge.js';</script>
<focsd-badge>Draft</focsd-badge>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
tone | tone | 'neutral' | 'info' | 'positive' | 'caution' | 'critical' | neutral |
dot | dot | boolean | false |
count | count | number | undefined | — |
max | max | number | 99 |
placement | placement | BadgePlacement | top-end |
label | label | string | — |
color | color | string | — |
Slots
| Slot | Description |
|---|---|
(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).
| Part | Description |
|---|---|
badge | The inline badge (without `dot` or `count`). |
anchor | The wrapper around the anchor (with `dot` or `count`). |
indicator | The dot or the count at the anchor's corner; hidden from assistive technology. |
hidden-text | Visually hidden text that names the indicator. |
Accessibility
- Plain inline text: the words carry the meaning, the tone color only reinforces it.
Indicator
- With
dotorcount, 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’slabel("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
countof 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. placementpicks the corner:top-end(the default),top-start,bottom-endorbottom-start. Start and end follow the reading direction, sotop-endis 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.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.