- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Card
- Checkbox
- Collapsible
- Combobox
- Context Menu
- Date Picker (Lite)
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP (Lite)
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
import { Badge } from "@/components/ui/badge"
export default function BadgeDemo() {
return (
<div class="flex w-full flex-wrap justify-center gap-2">
<Badge>Badge</Badge>
<Badge variant="secondary">Secondary</Badge>
<Badge variant="destructive">Destructive</Badge>
<Badge variant="outline">Outline</Badge>
</div>
)
}Installation
pnpm dlx shadcnui-hono-jsx@latest add badgenpx shadcnui-hono-jsx@latest add badgeyarn dlx shadcnui-hono-jsx@latest add badgebunx shadcnui-hono-jsx@latest add badgeUsage
import { Badge } from "@/components/ui/badge"<Badge variant="default | outline | secondary | destructive">Badge</Badge>Variants
Use the variant prop to change the variant of the badge.
import { Badge } from "@/components/ui/badge"
export function BadgeVariants() {
return (
<div class="flex flex-wrap gap-2">
<Badge>Default</Badge>
<Badge variant="secondary">Secondary</Badge>
<Badge variant="destructive">Destructive</Badge>
<Badge variant="outline">Outline</Badge>
<Badge variant="ghost">Ghost</Badge>
</div>
)
}With Icon
You can render an icon inside the badge. Use data-icon="inline-start" to render the icon on the left and data-icon="inline-end" to render the icon on the right.
import { BadgeCheck, BookmarkIcon } from "@/components/icons"
import { Badge } from "@/components/ui/badge"
export function BadgeWithIconLeft() {
return (
<div class="flex flex-wrap gap-2">
<Badge variant="secondary">
<BadgeCheck data-icon="inline-start" />
Verified
</Badge>
<Badge variant="outline">
Bookmark
<BookmarkIcon data-icon="inline-end" />
</Badge>
</div>
)
}With Spinner
You can render a spinner inside the badge. Remember to add the data-icon="inline-start" or data-icon="inline-end" prop to the spinner.
import { Badge } from "@/components/ui/badge"
import { Spinner } from "@/components/ui/spinner"
export function BadgeWithSpinner() {
return (
<div class="flex flex-wrap gap-2">
<Badge variant="destructive">
<Spinner data-icon="inline-start" />
Deleting
</Badge>
<Badge variant="secondary">
Generating
<Spinner data-icon="inline-end" />
</Badge>
</div>
)
}Link
Use the render prop to render a link as a badge.
import { ArrowUpRightIcon } from "@/components/icons"
import { Badge } from "@/components/ui/badge"
export function BadgeAsLink() {
return (
<Badge render={<a href="#link" />}>
Open Link <ArrowUpRightIcon data-icon="inline-end" />
</Badge>
)
}Custom Colors
You can customize the colors of a badge by adding custom classes such as bg-green-50 dark:bg-green-800 to the Badge component.
import { Badge } from "@/components/ui/badge"
export function BadgeCustomColors() {
return (
<div class="flex flex-wrap gap-2">
<Badge class="bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300">
Blue
</Badge>
<Badge class="bg-green-50 text-green-700 dark:bg-green-950 dark:text-green-300">
Green
</Badge>
<Badge class="bg-sky-50 text-sky-700 dark:bg-sky-950 dark:text-sky-300">
Sky
</Badge>
<Badge class="bg-purple-50 text-purple-700 dark:bg-purple-950 dark:text-purple-300">
Purple
</Badge>
<Badge class="bg-red-50 text-red-700 dark:bg-red-950 dark:text-red-300">
Red
</Badge>
</div>
)
}RTL
To enable RTL support in shadcn/ui, see the RTL configuration guide.
// This example sets dir and uses useTranslation because this site is not RTL.
// In an RTL app you won't need them; see the RTL guide.
import { BadgeCheck, BookmarkIcon } from "@/components/icons"
import {
type Translations,
useTranslation,
} from "@/components/language-selector"
import { Badge } from "@/components/ui/badge"
const translations: Translations = {
en: {
dir: "ltr",
values: {
badge: "Badge",
secondary: "Secondary",
destructive: "Destructive",
outline: "Outline",
verified: "Verified",
bookmark: "Bookmark",
},
},
ar: {
dir: "rtl",
values: {
badge: "شارة",
secondary: "ثانوي",
destructive: "مدمر",
outline: "مخطط",
verified: "متحقق",
bookmark: "إشارة مرجعية",
},
},
he: {
dir: "rtl",
values: {
badge: "תג",
secondary: "משני",
destructive: "הרסני",
outline: "קווי מתאר",
verified: "מאומת",
bookmark: "סימנייה",
},
},
}
export function BadgeRtl() {
const { dir, t } = useTranslation(translations, "ar")
return (
<div class="flex w-full flex-wrap justify-center gap-2" dir={dir}>
<Badge>{t.badge}</Badge>
<Badge variant="secondary">{t.secondary}</Badge>
<Badge variant="destructive">{t.destructive}</Badge>
<Badge variant="outline">{t.outline}</Badge>
<Badge variant="secondary">
<BadgeCheck data-icon="inline-start" />
{t.verified}
</Badge>
<Badge variant="outline">
{t.bookmark}
<BookmarkIcon data-icon="inline-end" />
</Badge>
</div>
)
}Notes
renderis supported on the server (element or function), like Base UI.- Accepts
classinstead ofclassName. - Upstream documentation: shadcn/ui Badge. See also Differences from shadcn/ui.
API Reference
Badge
The Badge component displays a badge or a component that looks like a badge.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | "default" |
className | string | - |