Skip to content
Slotted

Badge

A short, non-interactive label or count that states the status of the element beside it or sits on its corner.

SO-10482Shipped
SO-10483Awaiting pickup
SO-10484Payment failed
SO-10485Draft

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes

Tone and variant

tone picks the semantic color: accent, secondary, info, success, warning or danger. variant picks how the tone is painted: solid fills the badge, soft tints it, outline draws the edge alone. The default is secondary and soft. Pair the color with words, as the status names here do, because color alone is not a signal.

AccentSecondaryInfoSuccessWarningDanger
AccentSecondaryInfoSuccessWarningDanger
AccentSecondaryInfoSuccessWarningDanger

Sizes

size takes the control scale: sm, md and lg. A badge shrinks and grows with the controls it sits beside, so a table of sm buttons takes sm badges.

SmallMediumLarge

Shapes

pill rounds the badge fully and square rounds it by one step. dot draws no count: its children are its only content, so the words of a dot go in a visually hidden element, and a text beside it states what it means. The dot below carries the hidden word “Online” next to the visible label of the service.

Backorderedpill
Backorderedsquare
OnlineCarrier API

Count

count writes a number before any children and formats it for the locale. Above max, 99 by default, the badge shows the ceiling and a plus sign; max={false} in React and [max]="false" in Angular removes the ceiling. locale sets the language of the digits and falls back to the defaults, then to the runtime. A count of zero removes the badge from the page, and showZero keeps it. In React the badge renders nothing; in Angular it takes display: none.

4Open orders
99+Backorders, above the default ceiling of 99
999+Pallets in transit, ceiling of 999
1.234.567Units shipped, no ceiling, de-DE digits
0Open returns, zero shown

Beside a title

A badge is taller than a line of text at the same size, so a title that carries one grows its row. inline draws the badge inside the line: the line keeps its height and the text under it keeps its distance.

Glyphs

A glyph goes before or after the label: the start and end props in React, and an element carrying slBadgeStart or slBadgeEnd in Angular. The part sizes and centers the glyph. In Angular the start part draws first and the end part last, whatever their order in the template.

Due in 2 daysUnassigned

On the corner of an element

BadgeAnchor in React, and slBadgeAnchor on the element around the host in Angular, places the badge on a corner of the host. React renders a wrapper span; Angular writes the directive on an element the page already has. The badge comes after the host in document order, so it is read after the host. When the host is interactive and its name must carry the count, point aria-describedby from the host to the id of the badge, as the second host does, or put the count in the host’s aria-label. A badge is not focusable and takes no press, so the host stays the only control.

7unread notifications99+unread messages

Placement

placement chooses the corner: top-end, the default, top-start, bottom-end or bottom-start. Start and end follow the inline direction, so a right-to-left document mirrors them.

New messagestop-end
New messagestop-start
New messagesbottom-end
New messagesbottom-start

Overlap and offset

overlap states the shape of the host. rectangle, the default, sets the badge on the corner point; circle moves it in far enough to meet the curve. offset then moves it by x and y pixels from the computed corner. x runs along the inline axis and mirrors with the document.

MOOnlinerectangle
MOOnlinecircle
MOOnlinecircle, offset 2px

Live updates

live sets whether a change to the badge is announced. off, the default, announces nothing. polite writes role="status" and assertive writes role="alert". A role written on the badge is kept. Use polite for a count that changes while the person works, and assertive only for a failure. Press each button and the matching count changes.

Queued3
Failed1

A badge that navigates

The root takes the element the page chooses: the render prop in React, and the directive written on an a in Angular. A badge on an anchor is focusable and draws the focus ring; a badge on a span is not a command.

Defaults

BadgeDefaultsProvider in React and provideBadgeDefaults in Angular set tone, variant, size, shape, max and locale once for every badge below them. A badge that states a value of its own keeps it, as the rejected badge does with size and variant.

PendingApprovedRejected
12.480Units in stock

Accessibility

  • There is no badge pattern in the WAI-ARIA Authoring Practices — the pattern index carries no entry — and there is no badge role. The applicable guidance is the status role in WAI-ARIA 1.2, and WCAG 2.2 1.4.1 Use of Color, 1.4.11 Non-text Contrast and 4.1.3 Status Messages.
  • The root is a span with no role. What a badge means comes from where it sits.
  • live is the announcement policy for a badge whose value changes: polite writes role="status", whose implicit aria-live and aria-atomic are what a changing count needs; assertive writes role="alert". The default is off, so that only the badges the page marks announce.
  • A dot has no text for a screen reader to read. Put the words beside it — a VisuallyHidden inside the badge — because color alone is not a signal. Inside a badge that element is out of flow, so it takes no space and the gap reserves nothing for it.
  • The dot is the only badge whose whole meaning is a graphic, so its rim is --slotted-border-strong: the one border token the theme holds to 3:1 against the surface. A pill or a square carries text, so its edge is decoration.
  • BadgeAnchor wraps its host rather than rewriting it. The badge is read after the host in document order. When the host is interactive and its name must carry the count, either wire aria-describedby from the host to the badge’s own id, or name the count in the host’s aria-label — “Inbox, 4 unread messages”.
  • A badge is not focusable and is never a command: it answers no hover and gives no press feedback. render can make the root an anchor, and Badge paints the focus ring for that case.
  • Under forced colors every tone ground becomes one system color, so Badge draws its edge in currentColor there. It is the only rule Badge writes for that mode.
  • A count of zero removes the badge from the page entirely rather than leaving an empty circle, so nothing announces a value that is no longer there.
  • A badge is one line. A string too long for its container is clipped with an ellipsis rather than reflowed, and the clipping is visual only: text-overflow shortens nothing, so the whole value stays in the DOM, stays in the accessibility tree, and a page search still finds it. A value that routinely needs more room is a Tag, not a Badge.
  • The count is formatted with Intl.NumberFormat, so a total reads 1.234 in de-DE and ١٬٢٣٤ in ar-EG. Set locale on the provider when the application server-renders counts above its grouping threshold.

API

badge

Props

tone'accent' | 'secondary' | 'info' | 'success' | 'warning' | 'danger'Default secondary
The semantic color of the badge. Six tones are available.
variant'solid' | 'soft' | 'outline'Default soft
How the tone is painted: filled, tinted or as an edge alone. All three variants draw the tone edge.
size'sm' | 'md' | 'lg'Default md
Type and glyph size follow the control scale, so a badge shrinks with the density of the controls beside it.
inlinebooleanDefault false
No taller than the line of text around it, for a title or a sentence: the line keeps its height and what is under it its distance. The badge takes its own size where the line has the room and one line of the text where it does not; its words are at most nine tenths of the text around it.
shape'pill' | 'square' | 'dot'Default pill
A dot draws no count. Its children are its only content, so the words of a dot go in a visually hidden element.
countnumber
The number the badge shows, written before any children and formatted for the locale.
maxnumber | falseDefault 99
The largest count written in full. Above it the badge shows the ceiling and a plus sign. false removes the ceiling.
showZerobooleanDefault false
Whether a count of zero is shown. When false, a count of zero removes the badge.
localestring
BCP 47 tag for the digits of count. Falls back to the provider, then to the runtime.
startReactNode
A glyph before the label, wrapped in the start part, which sizes and centers it.
endReactNode
A glyph after the label, wrapped in the end part.
live'off' | 'polite' | 'assertive'Default off
Announcement policy for a change to the badge: off, polite (role status) or assertive (role alert).
placement'top-end' | 'top-start' | 'bottom-end' | 'bottom-start'Default top-end
On BadgeAnchorThe corner of the host the badge sits on. Start and end mirror in a right-to-left document.
overlap'rectangle' | 'circle'Default rectangle
On BadgeAnchorThe shape of the host, which sets how far in from the corner the badge starts.
offset{ x?: number; y?: number }Default { x: 0, y: 0 }
On BadgeAnchorMoves the badge off the computed corner, in pixels. x runs along the inline axis and mirrors with the document.
render(props) => ReactNode
On Badge, BadgeAnchorRenders the root through another element, such as an anchor for a badge that navigates.
refRef<HTMLElement>
On every partReaches the native element. Each part extends the props of its own element.
BadgeDefaultsProvider{ tone, variant, size, shape, max, locale }
On a subtreeSets the defaults once for every badge under it. An explicit prop wins.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every badge inside it.

Badge tokens

TokenDefault
--slotted-badge-anchor-offset-x0px
--slotted-badge-anchor-offset-y0px
--slotted-badge-border-widthvar(--slotted-border-width-thin, 1px)
--slotted-badge-dot-border-colorvar(--slotted-border-strong, CanvasText)
--slotted-badge-font-familyvar(--slotted-control-font-family, sans-serif)
--slotted-badge-font-weightvar(--slotted-font-weight-medium, 500)
--slotted-badge-radiusvar(--slotted-radius-sm, 4px)
--slotted-badge-ring-colorvar(--slotted-surface, Canvas)
--slotted-badge-ring-widthvar(--slotted-border-width-thick, 2px)

Theme tokens it reads

TokenDefault
--slotted-border-strongSet per scheme by the theme
--slotted-border-width-thick2px
--slotted-border-width-thin1px
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-font-size-lgcomfortable 14px · compact 13px · dense 12px
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-font-size-smcomfortable 12px · compact 12px · dense 12px
--slotted-control-icon-size-mdcomfortable 16px · compact 14px · dense 13px
--slotted-control-icon-size-smcomfortable 14px · compact 13px · dense 12px
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-weight-medium500
--slotted-line-height-xs1.4
--slotted-radius-full9999px
--slotted-radius-sm4px
--slotted-space-10.125rem
--slotted-space-20.25rem
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-surfaceSet per scheme by the theme
--slotted-text-box-edgecap alphabetic
--slotted-tone-accent-borderSet per scheme by the theme
--slotted-tone-accent-on-solidSet per scheme by the theme
--slotted-tone-accent-solidSet per scheme by the theme
--slotted-tone-accent-surfaceSet per scheme by the theme
--slotted-tone-accent-textSet per scheme by the theme
--slotted-tone-danger-borderSet per scheme by the theme
--slotted-tone-danger-on-solidSet per scheme by the theme
--slotted-tone-danger-solidSet per scheme by the theme
--slotted-tone-danger-surfaceSet per scheme by the theme
--slotted-tone-danger-textSet per scheme by the theme
--slotted-tone-info-borderSet per scheme by the theme
--slotted-tone-info-on-solidSet per scheme by the theme
--slotted-tone-info-solidSet per scheme by the theme
--slotted-tone-info-surfaceSet per scheme by the theme
--slotted-tone-info-textSet per scheme by the theme
--slotted-tone-secondary-borderSet per scheme by the theme
--slotted-tone-secondary-on-solidSet per scheme by the theme
--slotted-tone-secondary-solid-hoverSet per scheme by the theme
--slotted-tone-secondary-surfaceSet per scheme by the theme
--slotted-tone-secondary-textSet per scheme by the theme
--slotted-tone-success-borderSet per scheme by the theme
--slotted-tone-success-on-solidSet per scheme by the theme
--slotted-tone-success-solidSet per scheme by the theme
--slotted-tone-success-surfaceSet per scheme by the theme
--slotted-tone-success-textSet per scheme by the theme
--slotted-tone-warning-borderSet per scheme by the theme
--slotted-tone-warning-on-solidSet per scheme by the theme
--slotted-tone-warning-solidSet per scheme by the theme
--slotted-tone-warning-surfaceSet per scheme by the theme
--slotted-tone-warning-textSet per scheme by the theme