ComponentsNew
Badge
Displays a badge or a component that looks like a badge. Use badges for labeling, categorization, and status indication.
Variants
Badges come in multiple variants for different purposes.
DefaultSecondaryOutlineDestructive
Use Cases
Status Indicators
ActivePendingInactive
Tags & Categories
ReactTypeScriptTailwind CSS
Notifications
Messages3
Version Labels
v1.0.0BetaDeprecated
Installation
Copy and paste the following code into your project:
components/ui/badge.tsxtsx
1import * as React from "react";2import { cn } from "@/lib/utils";34interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {5 variant?: "default" | "secondary" | "outline" | "destructive";6}78const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(9 ({ className, variant = "default", ...props }, ref) => {10 return (11 <span12 ref={ref}13 className={cn(14 "inline-flex items-center rounded-md px-2 py-0.5 text-xs font-medium transition-colors",15 {16 "bg-primary text-primary-foreground": variant === "default",17 "bg-secondary text-secondary-foreground": variant === "secondary",18 "border border-input bg-background": variant === "outline",19 "bg-destructive text-destructive-foreground": variant === "destructive",20 },21 className22 )}23 {...props}24 />25 );26 }27);28Badge.displayName = "Badge";2930export { Badge };Usage
import { Badge } from "@/components/ui/badge";
export default function Example() {
return <Badge variant="secondary">New Feature</Badge>;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "secondary" | "outline" | "destructive" | "default" | The visual style of the badge |
className | string | - | Additional CSS classes |