Badge

A count or status attached to content.

  • Composed
  • In the first release
import { Badge, badgePrimitive } from "nitro-ui-sdk/badge";
HeroUI Native
Badge (Pro)
Expo UI
BadgeBadgedBox
  • Badge example screen, light appearance
    Light
  • Badge example screen, dark appearance
    Dark
On this page

Badge marks a count, a short status, or a dot on a corner. Use it for unread counts and small statuses. For a sentence, use Alert. For a person, use Avatar and put the badge on it with Badge.Anchor.

Counts above maxCount render as 99+. The accessible name stays the full count.

Anatomy

<Badge.Anchor>
  <Avatar.Root name="Ada Lovelace" size="lg" />
  <Badge.Root count={3} intent="danger" variant="solid" size="sm" />
</Badge.Anchor>
Part Description
Root The pill, the dot, or both.
Label The visible text.
Dot A small status mark.
Anchor Places the last child on a corner of the children before it.

Usage

import { Badge } from "nitro-ui-sdk/badge";

export function Unread() {
  return <Badge.Root count={3} intent="danger" variant="solid" />;
}

Variants and sizes

intent is default, accent, success, warning, or danger. variant is solid, soft, or outline. soft is the default. size is sm, md, or lg. md is the default.

<>
  <Badge.Root label="New" intent="accent" variant="outline" size="sm" />
  <Badge.Root dot intent="success" accessibilityLabel="Online" />
</>

States

A badge is not pressed, disabled, or busy. dot draws a mark. With no label and no count, the badge is only that mark. decorative removes the accessible name when a parent already describes the status.

Controlled

A badge has no value of its own. Pass count or label from the parent.

<Badge.Root count={count} maxCount={99} intent="danger" />

formatBadgeCount(120) is "99+". The spoken label for that count is "120" unless you pass accessibilityLabel.

Liquid Glass

Badge does not draw Liquid Glass. Fills, soft fills, and borders come from the semantic palette.

Props

Root

Prop Type Default Description
label string — Visible and spoken text. Wins over count.
count number — Numeric value. Display is capped.
maxCount number 99 Cap before the label becomes 99+.
accessibilityLabel string full count or label Spoken name.
intent "default" | "accent" | "success" | "warning" | "danger" "default" Color.
variant "solid" | "soft" | "outline" "soft" Fill treatment.
size "sm" | "md" | "lg" "md" Height and type size.
dot boolean false Draws the status mark.
decorative boolean false Hides the badge from assistive tech.
styles BadgeStyles — Per-part style resolvers.
api Controller<BadgeActions> — Attached controller.
agentId string — Stable agent id.
layout layout — Extra layout merged onto the root.

Anchor

Prop Type Default Description
placement "top-end" | "top-start" | "bottom-end" | "bottom-start" "top-end" Corner for the last child.
layout layout — Layout of the wrapping box.

The last child is the badge. Everything before it is the content.

Controller API

import { badgePrimitive } from "nitro-ui-sdk/badge";

const api = badgePrimitive.createApi();
api.current?.getState();
Action Signature Result
getState () => BadgeState Display label, spoken label, count, whether a dot is showing, and the intent.

Styles

The resolver receives tokens, variant, size, and state.

<Badge.Root
  count={3}
  intent="danger"
  styles={{
    label: ({ tokens, state }) => ({
      text: { color: state.intent === "danger" ? tokens.colors.dangerForeground : tokens.colors.foreground },
    }),
  }}
/>

Accessibility

Role text. The name is the spoken label: a custom accessibilityLabel, otherwise the full count, otherwise label. The visible string may be 99+ while the name is 120. A dot with no count still needs accessibilityLabel. decorative sets accessibilityHidden.

Agent API

Read-only. Role status through the text entry. The name is the spoken label, the value is the count when there is one, and the text is the visible label. A decorative badge does not register.

Platform notes

iOS Android
Drawing Composed from layout, text, and color. No custom native view. Same composition.
Verification Exercised by the iOS harness on the lanes simulator. No Kotlin was added for this family.