Badge

Badge is a small inline label for showing status, counts, categories, or short tags. It renders a span by default and can be swapped to another element through the render prop while keeping its styling.

Badge
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme detection failed · neutral
See how it was built

Installation

pnpm dlx shadcn@latest add @retroui/badge

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

Usage

usage.tsx
import { Badge } from "@/components/ui/badge"export function StatusBadge() {  return <Badge variant="secondary">Active</Badge>}
  • Show a status or state label such as Active, Pending, Draft, or Error next to a title or row.
  • Display a count or small piece of metadata such as New, 3, or Beta.
  • Tag or categorize items in a list, card, or table cell.
  • Provide a link-styled inline tag by passing an anchor through the render prop.

Examples

Default badge

A plain badge with the default primary variant for a new-item label.

default-badge.tsx
import { Badge } from "@/components/ui/badge"export function NewLabel() {  return <Badge>New</Badge>}

Variants

Shows the available visual variants for different statuses.

variants.tsx
import { Badge } from "@/components/ui/badge"export function StatusList() {  return (    <div className="flex flex-wrap gap-2">      <Badge variant="default">Default</Badge>      <Badge variant="secondary">Secondary</Badge>      <Badge variant="destructive">Failed</Badge>      <Badge variant="outline">Draft</Badge>      <Badge variant="ghost">Archived</Badge>      <Badge variant="link">Learn more</Badge>    </div>  )}

Rendering as a link

Uses the render prop to render the badge as an anchor so it becomes clickable.

rendering-as-a-link.tsx
import { Badge } from "@/components/ui/badge"export function VersionTag() {  return <Badge variant="outline" render={<a href="/changelog" />}>v2.1 changelog</Badge>}

Badge with an icon in a heading

Places a badge beside a title and includes an inline SVG icon that is automatically sized.

badge-with-an-icon-in-a-heading.tsx
import { Badge } from "@/components/ui/badge"function CheckIcon() {  return (    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>      <path d="M20 6 9 17l-5-5" />    </svg>  )}export function VerifiedTitle() {  return (    <h3 className="flex items-center gap-2">      Project Alpha      <Badge variant="secondary">        <CheckIcon />        Verified      </Badge>    </h3>  )}

API reference

PropTypeDefaultDescription
variant"default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | null | undefined"default"Selects the visual style of the badge from the badgeVariants cva definition.
classNamestring—Additional Tailwind classes merged onto the badge root with cn(), overriding conflicting defaults.
renderuseRender.RenderProp (a ReactElement or render function from @base-ui/react)<span>Replaces the default span with a custom element or component while keeping the badge classes and props merged. Inherits the span's render state (slot "badge" and variant).
...propsuseRender.ComponentProps<"span">—All other standard span HTML attributes (id, children, onClick, aria-*, data-*, etc.) are forwarded to the rendered element via mergeProps.

Accessibility

  • The default element is a span, which is not interactive and is announced as plain text; do not rely on it for clickable actions.
  • When passing render={<a href="..." />}, the badge becomes a real link, so ensure it has meaningful text and a visible focus state (focus-visible outline is built in).
  • Do not convey status by color alone; include a text label such as Failed or Active, which the default children already provide.
  • Set aria-invalid on a form-related wrapper to apply the destructive border style; the badge itself does not add ARIA roles.
  • Icons inside the badge are styled with pointer-events-none and size-3; add aria-hidden="true" to decorative SVGs so screen readers skip them.
  • If the count is meaningful to assistive technology, include context in text, for example "3 unread messages", instead of a bare number.

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 (retroui/badge) from its shadcn registry.1. Install it with: npx shadcn@latest add @retroui/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, className, render, ...props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Badge } from "@/components/ui/badge"export function StatusBadge() {  return <Badge variant="secondary">Active</Badge>}```

Files & dependencies

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

Looks similar, elsewhere