Badge
A 22px status mark at the 6px radius, with tone variants.
The status tones have set meanings: neutral for to do, draft or closed, info for in progress or issued, warning for in review or due, positive for done or paid, negative for overdue or failed. Each adds a dot, so the state never rests on colour alone.
Variants
NewBetaInternalArchivedBlocked4 comments
import { Badge } from "@/components/ui/badge"
export default function BadgeVariants() {
return (
<div className="flex flex-wrap items-center gap-2">
<Badge>New</Badge>
<Badge variant="secondary">Beta</Badge>
<Badge variant="outline">Internal</Badge>
<Badge variant="ghost">Archived</Badge>
<Badge variant="destructive">Blocked</Badge>
<Badge variant="link">4 comments</Badge>
</div>
)
}
Status tones
DraftIn progressIn reviewPaidOverdue
import { Badge } from "@/components/ui/badge"
export default function BadgeStatusTones() {
return (
<div className="flex flex-wrap items-center gap-2">
<Badge variant="neutral">Draft</Badge>
<Badge variant="info">In progress</Badge>
<Badge variant="warning">In review</Badge>
<Badge variant="positive">Paid</Badge>
<Badge variant="negative">Overdue</Badge>
</div>
)
}
With icon
v4.2.0release/4.2Changelog
import { ArrowUpRightIcon, GitBranchIcon, TagIcon } from "@keyline-icons/react"
import { Badge } from "@/components/ui/badge"
export default function BadgeWithIcon() {
return (
<div className="flex flex-wrap items-center gap-2">
<Badge variant="secondary">
<TagIcon data-icon="inline-start" />
v4.2.0
</Badge>
<Badge variant="outline">
<GitBranchIcon data-icon="inline-start" />
release/4.2
</Badge>
<Badge>
Changelog
<ArrowUpRightIcon data-icon="inline-end" />
</Badge>
</div>
)
}
As a link
import { Badge } from "@/components/ui/badge"
export default function BadgeAsALink() {
return (
<div className="flex flex-wrap items-center gap-2">
<Badge render={<a href="https://ui.khaeli.com/r/badge.json" />}>Registry JSON</Badge>
<Badge variant="secondary" render={<a href="https://ui.khaeli.com/r/badge.json" />}>
Registry JSON
</Badge>
<Badge variant="outline" render={<a href="https://ui.khaeli.com/r/badge.json" />}>
Registry JSON
</Badge>
<Badge variant="link" render={<a href="https://ui.khaeli.com/r/badge.json" />}>
Registry JSON
</Badge>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/badgebunx --bun shadcn@latest add @khaeli/badgeInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- @base-ui/react ^1.7.0
- class-variance-authority ^0.7.1
Keyboard
Tab- A badge is text and takes no focus. Rendered as a link with
render={<a href="…" />}, it is a tab stop with the focus ring. Enter- Follows a badge that is rendered as a link.
Accessible name
- A badge is read as its text, so the text must carry the state by itself: Overdue, not a bare red mark.
- An icon beside the text is decorative and needs no name.
- Rendered as a link, the badge is a link named by its text. The
linkvariant only looks like one: give it a realhrefthroughrender.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/badge.json