Skip to content

CdsBadge

A badge is a small marker in the corner of an element or next to it: a counter of unread messages, a "there is something new" dot, a short label. A badge is not interactive — it draws attention to the element it is attached to instead of acting on its own.

Storybook GitLab Figma
Test coverage: 100% — good coverage
API in specs
26 / 26 props, events, slots and exposed members with a test
Test cases
38 unit · 0 browser
Known bugs
1 pinned by an it.fails test
Code coverage
100% lines · 97.1% branches measured in v4.0.0-alpha.13
A11y (axe)
7 recommendations in 15 stories measured in v4.0.0-alpha.11

For a textual object status ("Done", "In progress") take CdsStatus, and CdsAvatar has a built-in badge prop for the common indicators on an avatar.

Anatomy ​

The badge attaches to the element from the default slot and is positioned relative to it. The content is a number or text from content, an icon from icon, or the markup from the badge slot.

Variations ​

Content ​

The content prop sets what the badge shows — most often a counter of events. By default the badge sits in the top right corner of the element from the slot.

The max prop caps the counter: anything above it collapses into "99+". Without max the value is printed in full.

Besides a number, content accepts a short text — a "new section" mark in a menu, for example. Here the badge is placed into the line by the inline prop — more on it in the positioning section.

The icon prop shows an icon instead of text.

Dot ​

The dot prop shrinks the badge to a dot and hides its content — only the "there is something new" signal is left. The diameter is changed via dot-size.

Colors ​

The color prop accepts any color alias of the design system, text-color changes the color of the content. By default the badge is red — the color of indication.

Positioning ​

By default the badge is positioned absolutely relative to the element from the slot. The location prop picks the corner.

The floating prop moves the badge 8 pixels away from the content, so it overlaps the element less. For fine-tuning there are offset-x and offset-y.

The inline prop puts the badge into the flow next to the content — as in the menu example above. location, floating and offset-* are ignored then.

Visibility ​

The model-value prop shows and hides the badge. The change of state is animated, and the animation is configured through transition.

Slots ​

SlotDescription
defaultThe element the badge is attached to
badgeBadge content. Replaces content and icon

Guidelines ​

Scenarios ​

Notification center ​

A counter on the notifications icon: max keeps the badge compact for any number of events, and model-value hides it once nothing is unread — an empty "0" does not hang on the icon.

Counters in menu items hint where to look. A badge with inline goes into the append slot of a list item, and once the section is opened model-value removes it. Open "Входящие" — the counter disappears.

Contacts online ​

A dot indicator shows the state without words: color="green" — the contact is online, neutral — not. inline puts the dot into the list row, and the label prop announces the state to screen readers.

API ​

Props

NameTypeDefaultDescription
colorstring | undefined—Component color
contentstring | number | undefined—Content displayed in the component.
dotboolean | undefined—Shrinks the component and hides its content, rendering it as a dot
dotSizestring | number | undefined—Dot size
floatingboolean | undefined—Moves the component further away from the content — an 8 pixel offset.
heightstring | number | undefined—Component height
iconIconValue | undefined—Icon shown inside the component. Ignored when the dot prop is set.
inlineboolean | undefined—Renders as an inline block instead of using absolute positioning. The location, floating and offset props are ignored.
labelstring | undefined'$cds.badge'Aria-label for the component. Falls back to the default value when not set.
locationAnchor | null | undefined'top end'Position of the element relative to its container, for example "top left", "center", "bottom right".
maxstring | number | undefined—Sets the maximum allowed value when content holds a number. If the number exceeds the maximum, a "+" suffix is added.
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined—Minimum component width
modelValueboolean | undefinedtrueControls whether the component is shown or hidden.
offsetXstring | number | undefined—Offset along the X axis
offsetYstring | number | undefined—Offset along the Y axis
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
textstring | number | undefined—Text displayed in the component.
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
transitionstring | boolean | (TransitionProps & { component?: Component | undefined; }) | null | undefined'fade-transition'Transition animation
widthstring | number | undefined—Component width

Slots

NameTypeDescription
badgeanySlot for the content placed inside the badge.
defaultanyDefault slot