Displays a small label, such as a status, a tag, or a count. Renders a span, or an a when href is set.
<script lang="ts">
import { Badge } from "#lib/components/ui/badge/index.js";
</script>
<Badge>Badge</Badge>pnx remote0 add https://plainsv.com/r/badge.jsonSet variant to default, secondary, destructive, outline, ghost, or link.
<Badge>Default</Badge>
<Badge variant="secondary">Secondary</Badge>
<Badge variant="destructive">Destructive</Badge>
<Badge variant="outline">Outline</Badge>
<Badge variant="ghost">Ghost</Badge>
<Badge variant="link">Link</Badge>Place an icon before or after the label. Icons scale with the size.
<script lang="ts">
import { Badge } from "#lib/components/ui/badge/index.js";
import { BadgeCheckIcon } from "@lucide/svelte";
</script>
<Badge variant="secondary"><BadgeCheckIcon />Verified</Badge>Set rounded="pill" for a pill counter. Tabular digits keep the width steady as the number changes.
<Badge rounded="pill" style="font-variant-numeric: tabular-nums">8</Badge>
<Badge rounded="pill" variant="destructive" style="font-variant-numeric: tabular-nums">99</Badge>Set href to render an a. Link badges darken or fill on hover and show a focus ring.
<script lang="ts">
import { Badge } from "#lib/components/ui/badge/index.js";
import { ArrowUpRightIcon } from "@lucide/svelte";
</script>
<Badge href="/docs/components">Components<ArrowUpRightIcon /></Badge>Set size to xs, sm, md, or lg. The default is md, like the shadcn badge, and the corner radius follows the size.
<Badge size="xs">Size xs</Badge>
<Badge size="lg">Size lg</Badge>Set rounded to xs through 4xl or pill to override the radius from the size.
<Badge rounded="pill">Rounded pill</Badge>The Badge props extend the native span attributes, or the a attributes when href is set.
interface BadgeBaseProps {
/** Visual style of the badge */
variant?: "default" | "secondary" | "destructive" | "outline" | "ghost" | "link";
/** Padding, text, and icon size on the shared scale; defaults to `md` */
size?: UiSize;
/** Corner radius; follows `size` when omitted */
rounded?: UiRounded;
}
type Props = BadgeBaseProps & ((CompPropsWithChild<"span"> & { href?: undefined }) | (CompPropsWithChild<"a"> & { href: string }));