<!-- index: /slotted/llms.txt -->
# badge

`data-ui="badge"` · Short label or count attached to an element.

## Minimal example

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const ORDERS = [
  { id: 'SO-10482', status: 'Shipped', tone: 'success' },
  { id: 'SO-10483', status: 'Awaiting pickup', tone: 'warning' },
  { id: 'SO-10484', status: 'Payment failed', tone: 'danger' },
  { id: 'SO-10485', status: 'Draft', tone: 'secondary' },
] as const;

export default function BadgeBasic() {
  return (
    <Stack gap={3}>
      {ORDERS.map((order) => (
        <Inline key={order.id} align="center" gap={3}>
          <Text numeric="tabular">{order.id}</Text>
          <Badge tone={order.tone}>{order.status}</Badge>
        </Inline>
      ))}
    </Stack>
  );
}
```

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | secondary | Badge | The semantic color of the badge. Six tones are available. |
| `variant` | `'solid' \| 'soft' \| 'outline'` | soft | Badge | How the tone is painted: filled, tinted or as an edge alone. All three variants draw the tone edge. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Badge | Type and glyph size follow the control scale, so a badge shrinks with the density of the controls beside it. |
| `inline` | `boolean` | false | Badge | 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'` | pill | Badge | A dot draws no count. Its children are its only content, so the words of a dot go in a visually hidden element. |
| `count` | `number` | — | Badge | The number the badge shows, written before any children and formatted for the locale. |
| `max` | `number \| false` | 99 | Badge | The largest count written in full. Above it the badge shows the ceiling and a plus sign. false removes the ceiling. |
| `showZero` | `boolean` | false | Badge | Whether a count of zero is shown. When false, a count of zero removes the badge. |
| `locale` | `string` | — | Badge | BCP 47 tag for the digits of count. Falls back to the provider, then to the runtime. |
| `start` | `ReactNode` | — | Badge | A glyph before the label, wrapped in the start part, which sizes and centers it. |
| `end` | `ReactNode` | — | Badge | A glyph after the label, wrapped in the end part. |
| `live` | `'off' \| 'polite' \| 'assertive'` | off | Badge | 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'` | top-end | BadgeAnchor | The corner of the host the badge sits on. Start and end mirror in a right-to-left document. |
| `overlap` | `'rectangle' \| 'circle'` | rectangle | BadgeAnchor | The shape of the host, which sets how far in from the corner the badge starts. |
| `offset` | `{ x?: number; y?: number }` | { x: 0, y: 0 } | BadgeAnchor | Moves the badge off the computed corner, in pixels. x runs along the inline axis and mirrors with the document. |
| `render` | `(props) => ReactNode` | — | Badge, BadgeAnchor | Renders the root through another element, such as an anchor for a badge that navigates. |
| `ref` | `Ref<HTMLElement>` | — | every part | Reaches the native element. Each part extends the props of its own element. |
| `BadgeDefaultsProvider` | `{ tone, variant, size, shape, max, locale }` | — | a subtree | Sets the defaults once for every badge under it. An explicit prop wins. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `tone` | `accent`, `secondary`, `info`, `success`, `warning`, `danger` | `secondary` |
| `variant` | `solid`, `soft`, `outline` | `soft` |
| `size` | `sm`, `md`, `lg` | `md` |
| `shape` | `pill`, `square`, `dot` | `pill` |
| `live` | `off`, `polite`, `assertive` | `off` |
| `placement` | `top-end`, `top-start`, `bottom-end`, `bottom-start` | `top-end` |
| `overlap` | `rectangle`, `circle` | `rectangle` |

## Rules

- 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.

## Tokens

`--slotted-badge-anchor-offset-x`, `--slotted-badge-anchor-offset-y`, `--slotted-badge-border-width`, `--slotted-badge-dot-border-color`, `--slotted-badge-font-family`, `--slotted-badge-font-weight`, `--slotted-badge-radius`, `--slotted-badge-ring-color`, `--slotted-badge-ring-width`, `--slotted-border-strong`, `--slotted-border-width-thick`, `--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-weight-medium`, `--slotted-line-height-xs`, `--slotted-radius-full`, `--slotted-radius-sm`, `--slotted-space-1`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-surface`, `--slotted-text-box-edge`, `--slotted-tone-accent-border`, `--slotted-tone-accent-on-solid`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-surface`, `--slotted-tone-accent-text`, `--slotted-tone-danger-border`, `--slotted-tone-danger-on-solid`, `--slotted-tone-danger-solid`, `--slotted-tone-danger-surface`, `--slotted-tone-danger-text`, `--slotted-tone-info-border`, `--slotted-tone-info-on-solid`, `--slotted-tone-info-solid`, `--slotted-tone-info-surface`, `--slotted-tone-info-text`, `--slotted-tone-secondary-border`, `--slotted-tone-secondary-on-solid`, `--slotted-tone-secondary-solid-hover`, `--slotted-tone-secondary-surface`, `--slotted-tone-secondary-text`, `--slotted-tone-success-border`, `--slotted-tone-success-on-solid`, `--slotted-tone-success-solid`, `--slotted-tone-success-surface`, `--slotted-tone-success-text`, `--slotted-tone-warning-border`, `--slotted-tone-warning-on-solid`, `--slotted-tone-warning-solid`, `--slotted-tone-warning-surface`, `--slotted-tone-warning-text`

## Examples

### A status beside the thing it describes

Excerpt — not a complete module

```tsx
<Heading level={3}>
  Invoice #4821 <Badge tone="warning">Pending</Badge>
</Heading>;
```

### A count on the corner of a control

Excerpt — not a complete module

```tsx
<BadgeAnchor>
  <IconButton aria-label="Notifications">
    <BellIcon />
  </IconButton>
  <Badge tone="danger" variant="solid" size="sm" count={unread} live="polite">
    <VisuallyHidden>unread notifications</VisuallyHidden>
  </Badge>
</BadgeAnchor>;
```

### The count inside the host’s own description

Excerpt — not a complete module

```tsx
const id = useId();

<BadgeAnchor>
  <button aria-describedby={id} type="button">
    Inbox
  </button>
  <Badge count={4} id={id} size="sm" tone="danger" variant="solid">
    <VisuallyHidden>unread messages</VisuallyHidden>
  </Badge>
</BadgeAnchor>;
```

### A dot, and the words it cannot say

Excerpt — not a complete module

```tsx
<Inline align="center" gap={3}>
  <Badge shape="dot" tone="success" variant="solid">
    <VisuallyHidden>Online</VisuallyHidden>
  </Badge>
  <Text>Deployed</Text>
</Inline>;
```

### Presence on a round host

Excerpt — not a complete module

```tsx
<BadgeAnchor overlap="circle" placement="bottom-end">
  <Avatar name="André Lopes" />
  <Badge shape="dot" size="sm" tone="success" variant="solid">
    <VisuallyHidden>Online</VisuallyHidden>
  </Badge>
</BadgeAnchor>;
```

### A badge that navigates

Excerpt — not a complete module

```tsx
<Badge render={(props) => <a {...props} href="/releases/4.2.0" />} tone="accent" variant="outline">
  v4.2.0
</Badge>;
```

### One decision for every badge in the application

Excerpt — not a complete module

```tsx
<BadgeDefaultsProvider locale="pt-BR" max={999} size="sm">
  <App />
</BadgeDefaultsProvider>;
```

### anchor.tsx

Example

```tsx
import { useId } from 'react';
import { Badge, BadgeAnchor } from '@slotted/react/badge';
import { Button, IconButton } from '@slotted/react/button';
import { Glyph } from '@slotted/react/icon';
import { Inline } from '@slotted/react/inline';
import { VisuallyHidden } from '@slotted/react/visually-hidden';

export default function BadgeAnchored() {
  const inboxCountId = useId();

  return (
    <Inline align="center" gap={8}>
      <BadgeAnchor>
        <IconButton aria-label="Notifications">
          <Glyph name="bell" />
        </IconButton>
        <Badge count={7} size="sm" tone="danger" variant="solid">
          <VisuallyHidden>unread notifications</VisuallyHidden>
        </Badge>
      </BadgeAnchor>
      <BadgeAnchor>
        <Button aria-describedby={inboxCountId}>Inbox</Button>
        <Badge count={128} id={inboxCountId} size="sm" tone="accent" variant="solid">
          <VisuallyHidden>unread messages</VisuallyHidden>
        </Badge>
      </BadgeAnchor>
    </Inline>
  );
}
```

### appearance.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';

const VARIANTS = ['solid', 'soft', 'outline'] as const;
const TONES = [
  { tone: 'accent', label: 'Accent' },
  { tone: 'secondary', label: 'Secondary' },
  { tone: 'info', label: 'Info' },
  { tone: 'success', label: 'Success' },
  { tone: 'warning', label: 'Warning' },
  { tone: 'danger', label: 'Danger' },
] as const;

export default function BadgeAppearance() {
  return (
    <Stack gap={3}>
      {VARIANTS.map((variant) => (
        <Inline key={variant} gap={2}>
          {TONES.map(({ tone, label }) => (
            <Badge key={tone} tone={tone} variant={variant}>
              {label}
            </Badge>
          ))}
        </Inline>
      ))}
    </Stack>
  );
}
```

### count.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function BadgeCount() {
  return (
    <Stack gap={3}>
      <Inline align="center" gap={3}>
        <Badge count={4} tone="info" />
        <Text>Open orders</Text>
      </Inline>
      <Inline align="center" gap={3}>
        <Badge count={128} tone="warning" />
        <Text>Backorders, above the default ceiling of 99</Text>
      </Inline>
      <Inline align="center" gap={3}>
        <Badge count={1204} max={999} tone="warning" />
        <Text>Pallets in transit, ceiling of 999</Text>
      </Inline>
      <Inline align="center" gap={3}>
        <Badge count={1234567} locale="de-DE" max={false} tone="success" />
        <Text>Units shipped, no ceiling, de-DE digits</Text>
      </Inline>
      <Inline align="center" gap={3}>
        <Badge count={0} showZero tone="secondary" />
        <Text>Open returns, zero shown</Text>
      </Inline>
    </Stack>
  );
}
```

### defaults.tsx

Example

```tsx
import { Badge, BadgeDefaultsProvider } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function BadgeDefaults() {
  return (
    <BadgeDefaultsProvider locale="de-DE" max={false} size="sm" variant="outline">
      <Stack gap={3}>
        <Inline gap={2}>
          <Badge tone="info">Pending</Badge>
          <Badge tone="success">Approved</Badge>
          <Badge size="md" tone="danger" variant="solid">
            Rejected
          </Badge>
        </Inline>
        <Inline align="center" gap={3}>
          <Badge count={12480} tone="secondary" />
          <Text>Units in stock</Text>
        </Inline>
      </Stack>
    </BadgeDefaultsProvider>
  );
}
```

### glyphs.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Glyph } from '@slotted/react/icon';
import { Inline } from '@slotted/react/inline';

export default function BadgeGlyphs() {
  return (
    <Inline gap={3}>
      <Badge start={<Glyph name="clock" />} tone="warning">
        Due in 2 days
      </Badge>
      <Badge end={<Glyph name="inbox" />} tone="info">
        Unassigned
      </Badge>
    </Inline>
  );
}
```

### link.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';

export default function BadgeLink() {
  return (
    <Badge
      render={(props) => <a {...props} href="#backordered" />}
      tone="warning"
      variant="outline"
    >
      Backordered
    </Badge>
  );
}
```

### live.tsx

Example

```tsx
import { useState } from 'react';
import { Badge } from '@slotted/react/badge';
import { Button } from '@slotted/react/button';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function BadgeLive() {
  const [queued, setQueued] = useState(3);
  const [failed, setFailed] = useState(1);

  return (
    <Stack gap={4}>
      <Inline align="center" gap={3}>
        <Button onClick={() => setQueued(queued + 1)} size="sm" variant="outline">
          Queue order
        </Button>
        <Text>Queued</Text>
        <Badge count={queued} live="polite" tone="info" />
      </Inline>
      <Inline align="center" gap={3}>
        <Button onClick={() => setFailed(failed + 1)} size="sm" variant="outline">
          Fail payment
        </Button>
        <Text>Failed</Text>
        <Badge count={failed} live="assertive" tone="danger" />
      </Inline>
    </Stack>
  );
}
```

### overlap.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Badge, BadgeAnchor } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';
import { VisuallyHidden } from '@slotted/react/visually-hidden';

export default function BadgeOverlap() {
  return (
    <Inline gap={8}>
      <Stack gap={2}>
        <BadgeAnchor overlap="rectangle" placement="bottom-end">
          <Avatar name="Marta Okafor" size="lg" />
          <Badge shape="dot" size="sm" tone="success" variant="solid">
            <VisuallyHidden>Online</VisuallyHidden>
          </Badge>
        </BadgeAnchor>
        <Text size="sm" tone="muted">
          rectangle
        </Text>
      </Stack>
      <Stack gap={2}>
        <BadgeAnchor overlap="circle" placement="bottom-end">
          <Avatar name="Marta Okafor" size="lg" />
          <Badge shape="dot" size="sm" tone="success" variant="solid">
            <VisuallyHidden>Online</VisuallyHidden>
          </Badge>
        </BadgeAnchor>
        <Text size="sm" tone="muted">
          circle
        </Text>
      </Stack>
      <Stack gap={2}>
        <BadgeAnchor offset={{ x: 2, y: 2 }} overlap="circle" placement="bottom-end">
          <Avatar name="Marta Okafor" size="lg" />
          <Badge shape="dot" size="sm" tone="success" variant="solid">
            <VisuallyHidden>Online</VisuallyHidden>
          </Badge>
        </BadgeAnchor>
        <Text size="sm" tone="muted">
          circle, offset 2px
        </Text>
      </Stack>
    </Inline>
  );
}
```

### placement.tsx

Example

```tsx
import { Badge, BadgeAnchor } from '@slotted/react/badge';
import { IconButton } from '@slotted/react/button';
import { Glyph } from '@slotted/react/icon';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';
import { VisuallyHidden } from '@slotted/react/visually-hidden';

const PLACEMENTS = ['top-end', 'top-start', 'bottom-end', 'bottom-start'] as const;

export default function BadgePlacement() {
  return (
    <Inline gap={8}>
      {PLACEMENTS.map((placement) => (
        <Stack key={placement} gap={2}>
          <BadgeAnchor placement={placement}>
            <IconButton aria-label="Open inbox">
              <Glyph name="inbox" />
            </IconButton>
            <Badge shape="dot" size="sm" tone="danger" variant="solid">
              <VisuallyHidden>New messages</VisuallyHidden>
            </Badge>
          </BadgeAnchor>
          <Text size="sm" tone="muted">
            {placement}
          </Text>
        </Stack>
      ))}
    </Inline>
  );
}
```

### shapes.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';
import { VisuallyHidden } from '@slotted/react/visually-hidden';

export default function BadgeShapes() {
  return (
    <Stack gap={3}>
      <Inline align="center" gap={3}>
        <Badge shape="pill" tone="warning">
          Backordered
        </Badge>
        <Text size="sm" tone="muted">
          pill
        </Text>
      </Inline>
      <Inline align="center" gap={3}>
        <Badge shape="square" tone="warning">
          Backordered
        </Badge>
        <Text size="sm" tone="muted">
          square
        </Text>
      </Inline>
      <Inline align="center" gap={3}>
        <Badge shape="dot" tone="success" variant="solid">
          <VisuallyHidden>Online</VisuallyHidden>
        </Badge>
        <Text>Carrier API</Text>
      </Inline>
    </Stack>
  );
}
```

### sizes.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';

export default function BadgeSizes() {
  return (
    <Inline align="center" gap={3}>
      <Badge size="sm" tone="info">
        Small
      </Badge>
      <Badge size="md" tone="info">
        Medium
      </Badge>
      <Badge size="lg" tone="info">
        Large
      </Badge>
    </Inline>
  );
}
```
