Badge

Badge is a small, non-interactive inline label for statuses, counts, and tags, built on Base UI's useRender so it can render as a span by default or as another element such as an anchor or button. It is styled with cva variants for semantic colors, a gradient option, and six size presets.

Badge
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @honestui/badge

Requires @honestui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { Badge } from '@/components/ui/badge'export function Example() {  return <Badge variant='success' size='small'>Active</Badge>}
  • Show a status, state, or category next to text, such as Active, Error, or Beta.
  • Display a short count or tag, such as unread notifications or a labeled filter.
  • Highlight a small clickable chip by passing render={<a />} or render={<button />} to Badge.
  • Use the outline or gradient variants to add emphasis without a heavy background.

Examples

All semantic variants

Renders each color variant with the default size.

all-semantic-variants.tsx
import { Badge } from '@/components/ui/badge'export function VariantsExample() {  return (    <div className='flex flex-wrap gap-2'>      <Badge variant='default'>Default</Badge>      <Badge variant='secondary'>Secondary</Badge>      <Badge variant='outline'>Outline</Badge>      <Badge variant='success'>Success</Badge>      <Badge variant='warning'>Warning</Badge>      <Badge variant='error'>Error</Badge>      <Badge variant='gradient'>Gradient</Badge>    </div>  )}

Size presets

Shows the compact and regular sizes side by side.

size-presets.tsx
import { Badge } from '@/components/ui/badge'export function SizesExample() {  return (    <div className='flex items-center gap-2'>      <Badge size='micro' variant='neutral'>Micro</Badge>      <Badge size='small' variant='neutral'>Small</Badge>      <Badge size='regular' variant='neutral'>Regular</Badge>    </div>  )}

Count badge with an icon

Uses an inline SVG; the Badge class sizes it automatically.

count-badge-with-an-icon.tsx
import { Badge } from '@/components/ui/badge'export function InboxCountExample() {  return (    <Badge variant='accent' size='sm'>      <svg viewBox='0 0 24 24' fill='none' stroke='currentColor' strokeWidth='2' aria-hidden='true'>        <path d='M4 4h16v16H4z' />      </svg>      12    </Badge>  )}

Render as a link

Uses the render prop so the badge becomes an anchor with pointer cursor and focus ring.

render-as-a-link.tsx
import { Badge } from '@/components/ui/badge'export function LinkBadgeExample() {  return (    <Badge render={<a href='/changelog' />} variant='info'>      What's new    </Badge>  )}

API reference

PropTypeDefaultDescription
variant"default" | "destructive" | "outline" | "secondary" | "info" | "success" | "warning" | "error" | "neutral" | "accent" | "danger" | "gradient" | null | undefined"default"Color variant, derived from badgeVariants. Several variants share the same token colors (for example, destructive, error, and danger; secondary and neutral; default, info, and accent).
size"default" | "sm" | "lg" | "micro" | "small" | "regular" | null | undefined"default"Size preset controlling height, font size, letter spacing, line height, and the automatic size of nested SVG icons.
renderuseRender.RenderProp<"span">"span"Base UI render prop. Pass an element (for example <a href="..." />) or a render function to change the rendered element. Props are merged with the badge's default props.
classNamestring—Additional Tailwind classes merged with the variant classes via cn.
...propsuseRender.ComponentProps<"span">—All other span props are forwarded, including children, id, aria-* and data-* attributes. data-slot is set to "badge" by default and can be overridden.

Accessibility

  • Badge renders a span with no implicit role by default, so it is read as plain text. Add role='status' or aria-live when the content changes dynamically.
  • When the color alone conveys meaning (such as error versus success), include a text label so the status is not communicated by color only.
  • When rendered as a link or button via the render prop, the element keeps its native semantics, and the badge adds a pointer cursor and a visible focus-visible outline using the hui focus ring token.
  • On coarse pointers, the badge expands its tap target to at least 44px by 44px with an absolutely positioned ::after pseudo-element when it is interactive.
  • Nested SVG icons have pointer-events disabled, so clicks land on the badge itself. Provide aria-hidden='true' on decorative icons.
  • Disabled state is styled with opacity 50% and pointer-events none; ensure disabled interactive badges also set aria-disabled when the element is not a native disabled control.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Badge" component (honestui/badge) from its shadcn registry.1. Install it with: npx shadcn@latest add @honestui/badge2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: variant, size, render, className, ...props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Badge } from '@/components/ui/badge'export function Example() {  return <Badge variant='success' size='small'>Active</Badge>}```

Files & dependencies

  • badge.tsx→ components/ui/badge.tsx
dependencies@base-ui/reactclass-variance-authority

Looks similar, elsewhere