Badge
A small pill-shaped label used to annotate UI with status, counts, or categories. Reach for it to draw attention to a short piece of metadata sitting next to other content. Content is passed as children; the visual treatment is driven by the variant prop.
Variants
default for something the user picked or a live state, secondary for neutral metadata that shouldn't compete with the content, destructive for a failure.
<Badge>Live</Badge>
<Badge variant="secondary">Queued</Badge>
<Badge variant="destructive">Declined</Badge>Which surface it sits on
A chip on a Card uses secondary, contrasting against the surface underneath. A chip directly on the page background uses bg-card instead — bg-secondary is nearly invisible on bg-background in light mode. This is the one place the rule flips based on what's behind it.
Inside a card
<div class="flex items-center gap-3">
<span class="text-sm">On the page</span>
<Badge class="bg-card! text-foreground!">Draft</Badge>
</div>
<Card class="w-72">
<CardHeader>
<CardTitle>Inside a card</CardTitle>
</CardHeader>
<CardContent>
<Badge variant="secondary">Draft</Badge>
</CardContent>
</Card>Status and counts
A badge annotates something else — it is never the content itself. Beside a label it reads as that thing's state; holding a number it reads as a count of what the label names.
<div class="flex flex-col gap-3 text-sm">
<div class="flex items-center gap-2"><span>Deployment</span> <Badge>Live</Badge></div>
<div class="flex items-center gap-2">
<span>Build</span>
<Badge variant="secondary">Queued</Badge>
</div>
<div class="flex items-center gap-2">
<span>Payment</span>
<Badge variant="destructive">Declined</Badge>
</div>
<div class="flex items-center gap-2">
<span class="font-medium">Notifications</span>
<Badge variant="destructive">12</Badge>
</div>
</div>API
| Prop | Type | Default | Description |
|---|---|---|---|
children required | import('svelte').Snippet | Badge content. | |
variant | 'default'|'secondary'|'destructive' | 'default' | Visual treatment of the badge. |
class | string | Additional Tailwind classes merged onto the root element. |