← Gallery
Solid (primary role)
Neutral
Line
Critical
Badge
UI primitivebadgeA short, static label for a status, a category or a count.
Live preview
DefaultSecondaryOutlineDestructive
A short, static label for a status, a category or a count. It informs; it does not act. For a
selectable chip or filter use Toggle (or a Button at size xs); there is no separate chip component.
Live examples
defaultSolid (primary role)
Paid
secondaryNeutral
Paid
outlineLine
Paid
destructiveCritical
Paid
Anatomy
- Container — a
<span>(or the child element withasChild, for example a link). - Optional icon — 12px SVG before the text.
- Text — one to three words.
From the code
- Tokens consumed
accentaccent-foregrounddestructiveforegroundprimaryprimary-foregroundringsecondarysecondary-foreground- Radius
- fixed
rounded-md(not the recipe control radius) - Focus
- dark:focus-visible:ring-destructive/40 · focus-visible:border-ring · focus-visible:ring-[3px] · focus-visible:ring-destructive/20 · focus-visible:ring-ring/50
- Motion
- transition-[color,box-shadow]
Variants
| Code | Designer name | Use when |
|---|---|---|
| default | Solid (primary role) | The one label that should stand out in a group. |
| secondary | Neutral | Most labels: categories, counts, metadata. |
| outline | Line | Quiet labels in dense tables and lists. |
| destructive | Critical | An error or blocking status. |
States
| State | Looks | Note |
|---|---|---|
| Static | Per variant. | The normal case. |
| Link hover | Background at 90% when rendered as a link (asChild with <a>). | Only when the badge navigates. |
| Focus | 3px ring in the ring role at 50%, border in ring. | Only when focusable (link). |
| Invalid | Border and ring in destructive when aria-invalid. | Rare; inherited from the form styles. |
Do
- Pair colour with text or an icon; never let colour alone carry the status (DESIGN-LANGUAGE §41).
- Keep the text short and in one form across the product ("Paid", not "Payment completed" in one place and "Paid" in another).
- Use
secondaryby default and savedefaultfor the one label that matters.
Don't
- Don't attach a click handler to a badge; use
ToggleorButton. - Don't use
destructivefor a status that is not an error. - Don't invent a colour per category through
className; categories that need colour need tokens.
Known gaps
- Badge uses the
primaryandsecondaryroles while Button's primary usesbrand. In a skin whereprimaryandbranddiffer, a default badge and a primary button do not match. - The radius is a fixed
rounded-md, not the recipe control radius that Button and Tabs use. - The theme has
success,warningandinforoles but Badge has no variants for them; DESIGN-LANGUAGE §11 gives urgent and info badge colours as hex (#C85A54, #7A7A7A) instead of roles. - Link hover darkens by opacity (
/90), which DESIGN-LANGUAGE §46 rejects for buttons.
Sources: DESIGN-LANGUAGE §11 Badge color rules; §41 Accessibility (colour not alone); §46 Button design rules
Size
1.6 KB
Exports
1
Imports
4
Type
ui
Exports
BadgeImports
- react
- @radix-ui/react-slot
- class-variance-authority
- ./utils
Source
View on GitHub →import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "./utils";
const badgeVariants = cva(
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
secondary:
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
destructive:
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
outline:
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
},
},
defaultVariants: {
variant: "default",
},
},
);
function Badge({
className,
variant,
asChild = false,
...props
}: React.ComponentProps<"span"> &
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
const Comp = asChild ? Slot : "span";
return (
<Comp
data-slot="badge"
className={cn(badgeVariants({ variant }), className)}
{...props}
/>
);
}
export { Badge, badgeVariants };