Small labels for state, versions, plans and counts: six tones, three sizes, icons, clickable filters, a remove button, and BadgeGroup for +N overflow.
- Run status
- Plan labels
- Model names
- Beta flags
- Removable filters
Examples
Badge or Tag? A badge describes something the system knows: a state, a version, a plan, a count. Its × is for occasional dismissing. A Tag holds values people type or pick, like filters, recipients or labels on a task. Tags come in a TagGroup with arrow-key focus, selection and Backspace to remove. If users build the list, use Tag.
Installation
npx knowns-ui@latest add badgePaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Badge from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/badge
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add badge
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/badge.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/badge, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "badge" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- tone
"neutral"|"accent"|"info"|"success"|"warning"|"danger"- Default
"neutral" - Colour of the badge.
- variant
"soft"|"outline"|"solid"- Default
"soft" - Tinted fill, hairline outline, or solid fill for counts and highlights.
- size
"sm"|"md"|"lg"- Default
"md" - 20, 22 or 26px high.
- shape
"rounded"|"pill"- Default
"rounded" - Softly rounded corners, or fully round ends.
- dot
boolean- Default
false - Leading dot in the tone colour.
- icon
ReactNode- Leading glyph, logo (modelIcon) or tiny avatar, sized to the badge and hidden from screen readers.
- onClick
(e) => void- Renders the badge as a button with a focus ring. Add aria-pressed for toggles.
- onRemove
() => void- Adds a × button (its own tab stop). Never triggers onClick.
- removeLabel
string- Default
"Remove <label>" - Accessible name of the × button.
- disabled
boolean- Default
false - Dims the badge and disables its buttons.
- ...props
span / button attributes- className, title, aria-label, ref…
| Prop | Type | Default | Description |
|---|---|---|---|
| tone | "neutral" | "accent" | "info" | "success" | "warning" | "danger" | "neutral" | Colour of the badge. |
| variant | "soft" | "outline" | "solid" | "soft" | Tinted fill, hairline outline, or solid fill for counts and highlights. |
| size | "sm" | "md" | "lg" | "md" | 20, 22 or 26px high. |
| shape | "rounded" | "pill" | "rounded" | Softly rounded corners, or fully round ends. |
| dot | boolean | false | Leading dot in the tone colour. |
| icon | ReactNode | - | Leading glyph, logo (modelIcon) or tiny avatar, sized to the badge and hidden from screen readers. |
| onClick | (e) => void | - | Renders the badge as a button with a focus ring. Add aria-pressed for toggles. |
| onRemove | () => void | - | Adds a × button (its own tab stop). Never triggers onClick. |
| removeLabel | string | "Remove <label>" | Accessible name of the × button. |
| disabled | boolean | false | Dims the badge and disables its buttons. |
| ...props | span / button attributes | - | className, title, aria-label, ref… |
- BadgeGroup max
number- Show at most this many badges; the rest fold into "+N" (never "+1"). Its tooltip lists them and a click shows all.
- BadgeGroup size / shape
BadgeSize / BadgeShape- Default
"md" / "rounded" - Look of the "+N" badge: match your badges.
- BadgeGroup aria-label
string- Names the row (role="group").
| Prop | Type | Default | Description |
|---|---|---|---|
| BadgeGroup max | number | - | Show at most this many badges; the rest fold into "+N" (never "+1"). Its tooltip lists them and a click shows all. |
| BadgeGroup size / shape | BadgeSize / BadgeShape | "md" / "rounded" | Look of the "+N" badge: match your badges. |
| BadgeGroup aria-label | string | - | Names the row (role="group"). |
What it handles
- 01Offers six tones (neutral, accent, info, success, warning, danger) in three looks: soft, outline and solid.
- 02Comes in sizes sm, md and lg and in a rounded or full `pill` shape, with an optional leading `dot` or `icon`.
- 03Becomes a button when you pass `onClick`, with a focus ring, and supports `disabled` for both click and remove.
- 04Adds a small remove button with `onRemove`, named "Remove <label>" by default or by `removeLabel`, and a click on it never fires `onClick`.
- 05Stacks badges in BadgeGroup and folds the overflow behind a "+N" button that lists the hidden labels and reveals them when pressed.
- 06Never folds a single badge, since "+1" is no shorter than the badge itself.
States
- First render
- Nothing. It paints as it is
- none
- Tone or variant change
- Background, border and text colour change
- 180ms, ease out
- Hover on the remove button
- The button background deepens
- 120ms, ease out
- Group expands
- The hidden badges appear in place of the "+N" button
- none
- Reduced motion
- Colour changes land at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. It paints as it is | none |
| Tone or variant change | Background, border and text colour change | 180ms, ease out |
| Hover on the remove button | The button background deepens | 120ms, ease out |
| Group expands | The hidden badges appear in place of the "+N" button | none |
| Reduced motion | Colour changes land at once | 0ms |
Works with
- TooltipInstalled with it. The "+N" button of BadgeGroup shows the hidden labels in one.
- AvatarPairs with it: pass a tiny decorative avatar as the leading `icon`.
- TagPairs with it: Badge states a status, Tag holds a value people pick or type.
- Status dotPairs with it: a dot alone is enough where a label would be noise.
When to use
When to use
- Short status labels in a tone, such as Active, Failed or Beta.
When not to use
- Selectable or removable filters: use Tag.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Badge to my app and wire it to my own data.
- I need short status labels in a tone, such as Active, Failed or Beta. Set that up with the Knowns UI Badge.
- Which Badge props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "badge" }) and search_docs({ query: "badge" }).