Badge
A small label for statuses, counts, and tags on cards, tables, and nav items — with the neobrutalist borders-and-shadows treatment.
import { Badge } from "@/components/ui/badge"
export function BadgeDemo() {The badge is a compact inline label — a plain <span> with no primitive underneath, styled to the neobrutalist recipe: thick borders, hard shadows, and bold type. The render prop (via Base UI's useRender) lets any element — a link, a button — wear the badge styles.
Reach for it when:
- Statuses — "Active", "Draft", "Failed" on table rows and cards;
destructivefor errors. - Counts — unread messages, cart items, notification totals next to nav labels.
- Tags and metadata — categories on blog cards, plan tiers, version labels in docs.
Installation#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/badge.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/badge.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/badge.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/badge.json
Copy and paste the following code into your project.
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { Slot } from "radix-ui"
import { cn } from "@/lib/utils"
const badgeVariants = cva(
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded border-2 px-2 py-0.5 text-xs font-head font-medium whitespace-nowrap shadow-sm transition-all focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive [&>svg]:pointer-events-none [&>svg]:size-3!",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
secondary:
"bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
destructive:
"bg-destructive text-destructive-foreground [a]:hover:bg-destructive/90",
outline:
"bg-transparent text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
ghost:
"border-transparent bg-transparent shadow-none hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
link: "border-transparent bg-transparent shadow-none text-primary underline-offset-4 hover:underline",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Badge({
className,
variant = "default",
asChild = false,
...props
}: React.ComponentProps<"span"> &
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
const Comp = asChild ? Slot.Root : "span"
return (
<Comp
data-slot="badge"
data-variant={variant}
className={cn(badgeVariants({ variant }), className)}
{...props}
/>
)
}
export { Badge, badgeVariants }
Update the import paths to match your project setup.
Usage#
import { Badge } from "@/components/ui/badge"<Badge variant="default | secondary | destructive | outline | ghost | link">
Badge
</Badge>Examples#
Variants#
Use the variant prop to change the variant of the badge.
import { Badge } from "@/components/ui/badge"
export function BadgeVariants() {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 "lucide-react"
import { Badge } from "@/components/ui/badge"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"
Link#
Use the render prop to render a link as a badge.
import { ArrowUpRightIcon } from "lucide-react"
import { Badge } from "@/components/ui/badge"Custom Colors#
You can customize the colors of a badge by adding custom classes such as bg-chart-2 text-primary-foreground to the Badge component.
import { Badge } from "@/components/ui/badge"
export function BadgeCustomColors() {RTL#
To enable RTL support in Neobrutalism.com, see the RTL configuration guide.
"use client"
import * as React from "react"Accessibility#
The badge renders a plain <span> — screen readers get its text and nothing else, so don't let color alone carry the meaning: variant="destructive" announces the same as default, the text has to say "Failed". Bare counts need context — add an aria-label or visually hidden text so "3" reads as "3 unread notifications". When rendered as a link via the render prop, it's an ordinary anchor and the usual link semantics apply.
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 | - |