Liking cljdoc? Tell your friends :D

x-badge

A small indicator that displays a count, a text label, or a dot. Supports five semantic colour variants, two sizes, pill shape, and dot-only mode.


Tag

<x-badge></x-badge>

Attributes

AttributeTypeDefaultDescription
variantenum"neutral"Colour variant: neutral info success warning error
sizeenum"md"Size: sm md
countnumberNumeric value to display. Capped at max.
maxnumber99Maximum displayed count. Values above show as "<max>+".
textstringShort label string (e.g. "NEW", "BETA").
dotbooleanfalseDot-only mode — no text shown.
pillbooleanfalseFully rounded pill shape.
aria-labelstringOverrides the accessible label on the host.
aria-describedbystringReferences an element that describes the badge.

Display mode priority

ConditionModeRendered content
Slotted content presentslotCustom slotted content
count attribute presentcountNumber (capped at max)
text attribute presenttextText string
dot attribute presentdotDot, no text
None of the aboveemptyHidden

Properties

PropertyTypeRead-onlyReflects attribute
variantstringnovariant
sizestringnosize
pillbooleannopill
dotbooleannodot
countnumbernocount
maxnumbernomax
textstringnotext
aria-labelstringnoaria-label
aria-describedbystringnoaria-describedby
displayTextstringyes

displayText returns the currently rendered label string ("7", "99+", "NEW", etc.) or null when the badge is in dot, slot, or empty mode.


Parts

PartDescription
baseOuter container element
labelText content <span>

Examples

Colour variants

<x-badge variant="neutral">Neutral</x-badge>
<x-badge variant="info">Info</x-badge>
<x-badge variant="success">Success</x-badge>
<x-badge variant="warning">Warning</x-badge>
<x-badge variant="error">Error</x-badge>

Count with cap

<x-badge variant="error" count="7"></x-badge>
<x-badge variant="error" count="999" max="99"></x-badge>

Text labels

<x-badge variant="success" text="NEW"></x-badge>
<x-badge variant="warning" text="BETA"></x-badge>

Small size

<x-badge variant="info" size="sm" count="5"></x-badge>

Dot

<x-badge variant="error" dot></x-badge>

Pill

<x-badge variant="success" pill count="3"></x-badge>

CSS custom properties

PropertyDefault (light)Description
--x-badge-bgrgba(0,0,0,0.08)Background colour
--x-badge-colorrgba(0,0,0,0.80)Text colour
--x-badge-borderrgba(0,0,0,0.12)Border colour
--x-badge-font-size0.75remFont size (sm: 0.6875rem)
--x-badge-height1.25remMin height (sm: 1rem)
--x-badge-padding0 0.375remInline padding (sm: 0 0.25rem)
--x-badge-radius0.25remBorder radius (sm: 0.1875rem)

Variant attributes (data-variant) set these properties automatically. Override on the host to customise individual badges:

x-badge.custom {
  --x-badge-bg: #e0f2fe;
  --x-badge-color: #0369a1;
  --x-badge-border: #7dd3fc;
}

Accessibility

  • The inner container carries role="status" so screen readers announce badge content as a live region.
  • Set aria-label to provide a meaningful label when the visual content alone is insufficient (e.g. aria-label="3 unread messages" on a count badge).
  • aria-describedby is set on the same role="status" element; reference IDs within the same document scope.
  • In dot mode the badge has no text — always provide aria-label when using dot.
  • Animations respect prefers-reduced-motion: reduce.

ClojureScript (hiccup renderer)

[:x-badge {:variant "error" :count "23"}]
[:x-badge {:variant "success" :text "NEW"}]
[:x-badge {:variant "error" :dot true}]

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close