Free shadcn/ui badge component for React — default, secondary, destructive and outline variants, with icon and status badge examples. Copy or install in one command.

Installation

1 Configure registry — once per project
{
  "registries": {
    "@designrevision": "https://registry.designrevision.com/r/{name}.json"
  }
}

Add to your existing components.json. Requires shadcn/ui v2.3+.

2 Install the component

Packages

@radix-ui/react-slot
class-variance-authority
utils

Props

variant = default
'default' | 'secondary' | 'destructive' | 'outline'

Visual style of the badge.

asChild = false
boolean

Render as the child element via Radix Slot — e.g. to wrap a link.

Extends React.HTMLAttributes<HTMLSpanElement> — all native span attributes are supported.

Copied!
components/ui/badge.tsx
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const badgeVariants = cva(
  "inline-flex w-fit shrink-0 items-center justify-center gap-1 whitespace-nowrap rounded-md border px-2 py-0.5 text-xs font-medium transition-colors [&>svg]:pointer-events-none [&>svg]:size-3",
  {
    variants: {
      variant: {
        default: "border-transparent bg-primary text-primary-foreground",
        secondary: "border-transparent bg-secondary text-secondary-foreground",
        destructive:
          "border-transparent bg-destructive text-destructive-foreground",
        outline: "text-foreground",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
)

export interface BadgeProps
  extends React.HTMLAttributes<HTMLSpanElement>,
    VariantProps<typeof badgeVariants> {
  asChild?: boolean
}

function Badge({ className, variant, asChild = false, ...props }: BadgeProps) {
  const Comp = asChild ? Slot : "span"
  return <Comp className={cn(badgeVariants({ variant }), className)} {...props} />
}

export { Badge, badgeVariants }

Examples

Variants

The four built-in variants — default, secondary, destructive, and outline — plus status badges with a leading icon.

Packages

lucide-react
badge

Props

No props documented yet.

Copied!
components/ui/badge-variants-01.tsx
import { BadgeCheck, Clock } from "lucide-react"

import { Badge } from "@/components/ui/badge"

export default function BadgeVariants01() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Badge>Default</Badge>
      <Badge variant="secondary">Secondary</Badge>
      <Badge variant="destructive">Destructive</Badge>
      <Badge variant="outline">Outline</Badge>
      <Badge variant="secondary">
        <BadgeCheck />
        Verified
      </Badge>
      <Badge variant="outline">
        <Clock />
        Pending
      </Badge>
    </div>
  )
}

Frequently asked questions

A badge is a small label for status, categories, counts, or tags. Use it to annotate other UI — a status next to a name, a count on a button, or a tag on a card.
Four variants: default, secondary, destructive, and outline, set with the variant prop. Each reads your theme tokens, so they follow light and dark mode automatically.
Yes. Drop a lucide-react icon inside the badge next to the text — the badge auto-sizes icons to 12px and spaces them, so no extra classes are needed.