Docs
Badge

Badge

A label that emphasizes an element that requires attention, or helps categorize with other similar elements.

Variants

graygray-subtle
blueblue-subtle
purplepurple-subtle
amberamber-subtle
redred-subtle
pinkpink-subtle
greengreen-subtle
tealteal-subtle
Trial
Turborepo

Installation

Copy and paste the following code into your project.

import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import type { LucideIcon } from "lucide-react"
 
import { cn } from "@/lib/utils"
 
const badgeVariants = cva(
  "inline-flex items-center justify-center rounded-full capitalize whitespace-nowrap",
  {
    variants: {
      variant: {
        gray: "bg-gray-700 text-white",
        "gray-subtle": "bg-gray-200 text-gray-1000",
        blue: "bg-blue-700 text-white",
        "blue-subtle": "bg-blue-200 text-blue-900",
        purple: "bg-purple-700 text-white",
        "purple-subtle": "bg-purple-200 text-purple-900",
        amber: "bg-amber-700 text-black",
        "amber-subtle": "bg-amber-200 text-amber-900",
        red: "bg-red-700 text-white",
        "red-subtle": "bg-red-200 text-red-900",
        pink: "bg-pink-700 text-white",
        "pink-subtle": "bg-pink-300 text-pink-900",
        green: "bg-green-700 text-white",
        "green-subtle": "bg-green-200 text-green-900",
        teal: "bg-teal-700 text-white",
        "teal-subtle": "bg-teal-300 text-teal-900",
        // TODO revisit this pink color
        trial: "bg-gradient-to-br from-blue-700 to-[#f81be6] text-white",
        turbo: "bg-gradient-to-br from-[#ff1e56] to-[#0096ff] text-white",
      },
      size: {
        sm: "px-1.5 h-5 text-[11px] gap-0.5 [&_svg]:w-[11px] [&_svg]:h-[11px]",
        md: "px-2.5 h-6 text-xs gap-1 [&_svg]:w-[14px] [&_svg]:h-[14px]",
        lg: "px-3 h-8 text-sm gap-1.5 [&_svg]:w-4 [&_svg]:h-4",
      },
    },
    defaultVariants: {
      variant: "gray",
      size: "md",
    },
  }
)
 
export interface BadgeProps
  extends React.HTMLAttributes<HTMLDivElement>,
    VariantProps<typeof badgeVariants> {
  icon?: React.ReactNode
}
 
// TODO add icons
function Badge({
  className,
  variant,
  size,
  icon,
  children,
  ...props
}: BadgeProps) {
  return (
    <span
      className={cn(badgeVariants({ variant, size }), className)}
      {...props}
    >
      {icon && <span>{icon}</span>}
      {children}
    </span>
  )
}
 
export { Badge, badgeVariants }

Update the import paths to match your project setup.

Usage

import { Badge } from "@/components/ui/badge"
<Badge variant="secondary">Badge</Badge>

You can use the badgeVariants helper to create a link that looks like a badge.

import { badgeVariants } from "@/components/ui/badge"
<Link className={badgeVariants({ variant: "outline" })}>Badge</Link>

Variants

graygray-subtle
blueblue-subtle
purplepurple-subtle
amberamber-subtle
redred-subtle
pinkpink-subtle
greengreen-subtle
tealteal-subtle
Trial
Turborepo

Sizes

SmallMediumLarge

Icons

graygraygraygraygraygray
blueblueblueblueblueblue
purplepurplepurplepurplepurplepurple
amberamberamberamberamberamber
redredredredredred
pinkpinkpinkpinkpinkpink
greengreengreengreengreengreen
tealtealtealtealtealteal