Badge
Status labels with colored dots, removable tags that slide closed and counts that roll to their new value.
Used in Pro blocks: Code Block, Subagents, Thinking, and 8 more
pnpm dlx shadcn@latest add https://hextaui.com/r/badge.jsonAdds the component, the HextaUI theme tokens and any HextaUI components it depends on.
Add the theme tokens to your global CSS, if you haven’t yet.
Install the dependencies.
pnpm add @base-ui/react @tabler/icons-react class-variance-authority cnCopy and paste the following code into your project.
components/ui/badge.tsx components/ui/number-flow.tsx lib/motion.ts Update the import paths to match your project setup.
The default outline appearance keeps a neutral surface and puts the status color on the dot or icon. Use appearance="solid" when the badge needs to stand out, or appearance="muted" for a quiet filled chip. shape="pill" rounds it fully.
sm, default and lg. Icons, dots, the close button and counts scale with the badge.
Add a <BadgeClose /> to make a badge removable. It shrinks closed and its neighbours slide into the gap, then focus moves to the next close button. Remove the item from your data in onOpenChangeComplete so the exit animation can finish first.
Pass open and onOpenChange to own the visibility. Setting open back to true brings the badge back with an enter animation.
<BadgeCount /> rolls only the digits that change, and caps at max (99 by default) with a plus sign. Screen readers always hear the real number.
Use render to make a badge a link or a button. It gains a hover tint, a press scale and a focus ring. aria-invalid shows the error state.
A badge never grows wider than its container. Long labels truncate with an ellipsis while icons and the close button stay visible.
Icons, the close button and the collapse animation follow the reading direction. Counts always read left to right.
These keys apply to <BadgeClose />.
| Key | Action |
|---|---|
| EnterSpace | Removes the badge. |
| BackspaceDelete | Removes the badge. |
| Tab | Moves to the next close button. After a removal, focus lands on the next close button, or the previous one when it was the last. |
- The close button is named after the badge, so a screen reader announces “Remove design” rather than a bare “Remove”. Pass
aria-labelto override it. <BadgeDot />is decorative and hidden from assistive tech. Keep the status in the text label.<BadgeCount />exposes the exact value even when the visible text is capped, like 99+.- The removal and count animations are skipped when reduced motion is on.
<Badge /> renders a <span> and accepts all of its attributes.
| Prop | Type | Default |
|---|---|---|
variantColors the dot and icons in outline, or the surface in solid. | "default" | "success" | "info" | "warning" | "destructive" | "default" |
appearance | "outline" | "solid" | "muted" | "outline" |
shape | "default" | "pill" | "default" |
size | "sm" | "default" | "lg" | "default" |
openControlled visibility. | boolean | – |
defaultOpen | boolean | true |
onOpenChangeCalled when BadgeClose is activated. | (open: boolean) => void | – |
onOpenChangeCompleteCalled after the exit animation finishes. Remove the item from your data here. | (open: boolean) => void | – |
render | ReactElement | (props, state) => ReactElement | <span> |
| Attribute | Description |
|---|---|
data-slot="badge" | Target badges in CSS. |
data-variant | The current variant. |
data-appearance | The current appearance. |
data-shape | The current shape. |
data-size | The current size. |
data-ending-style | Present while the badge animates out. |
--badge-accent | The status color used by dots and icons. Override it for a custom accent. |
--badge-height | The badge height. |
--badge-radius | The corner radius. The close button derives its own radius from it. |
| Prop | Type | Default |
|---|---|---|
pulseAdds a ping animation for live states. Off when reduced motion is on. | boolean | false |
| Attribute | Description |
|---|---|
data-slot="badge-dot" | Target dots in CSS. |
data-pulse | Present when pulse is on. |
| Prop | Type | Default |
|---|---|---|
children | ReactNode | <IconX /> |
aria-labelOverrides the automatic “Remove {label}” name. | string | – |
onClickCall event.preventDefault() to keep the badge open. | (event) => void | – |
| Attribute | Description |
|---|---|
data-slot="badge-close" | Target the close button in CSS. |
| Prop | Type | Default |
|---|---|---|
valueNegative and non-finite values show 0. | number | – |
maxValues above it show as max+. Pass Infinity for no cap. | number | 99 |
duration | number | 600 |
animated | boolean | true |
trendThe direction the digits spin. | "auto" | "up" | "down" | "shortest" | "auto" |
locales | Intl.LocalesArgument | – |
format | Intl.NumberFormatOptions | – |
| Attribute | Description |
|---|---|
data-slot="badge-count" | Target counts in CSS. |
- MotionThe easing curves, durations and reduced-motion check every component animates with, plus hooks for size morphs and sliding highlights.
- Number flowAnimated numbers where only the changed digits spin, with any Intl format and locale.
- AvatarUser photos with an initials fallback, status badges and stacked groups that collapse into a count.
- CardA surface for grouping content, with three variants, edge-to-edge media, concentric radii and whole-card links.
- ChartRecharts charts with themed colors, a tooltip and legend that read labels from one config, and keyboard navigation with a visible focus ring.
- Data tableA table for real data, with sorting, search, row selection, pinned columns, a sticky header and pagination.
Used in Pro blocks
Blocks that build on Badge.
- Code BlockCode blocks for AI answers. Highlighting keeps up with streaming, diffs can be accepted or rejected, and commands run in a terminal.
- SubagentsThe runs an agent hands to other agents, one line per run. Handles parallel runs, stop and retry, and a summary once each run is done.
- ThinkingThe thinking view of an AI chat. A live label follows each step, searches and sources fold into a trail, and citations sit beside the answer.
- API keysThe API keys page of an AI product. Handles a secret shown only once, revoke with undo and rotation with a grace period.
- BillingThe plan and usage page of an AI product. Handles credits running out mid-cycle, plan changes with proration and card errors.
- ModelsThe Models page of an AI product’s settings. Handles the default model and effort, providers and custom servers with a connection test.
Every block comes with HextaUI Pro, and Prompt Input is free.