Badge
Installation
npx @mielui/svelte add badgeyarn dlx @mielui/svelte add badgebunx @mielui/svelte add badgeUsage
Set href to render a link that accepts anchor attributes such as target, rel, and download. Without it, Badge renders a div. An empty href still renders a link, so narrow optional URLs before passing them.
Badges are static by default. Add role="status" only when a change to the badge text should be announced.
<script lang="ts">
import { Badge } from '@mielui/svelte/components/badge';
</script>
<Badge>New</Badge>
<Badge variant="outline" dot>Label</Badge>
<Badge variant="success">Active</Badge>
<Badge variant="error">Failed</Badge>Examples
Status list
A badge at the end of each row reports the state of that row.
- Production main ยท 2 minutes ago Live
- Preview feat/billing ยท building Building
- Staging release/0.3 ยท 1 hour ago Failed
- Archive v0.1 ยท last month Paused
Shapes
Badges are small flat pills that share one height. Only the outline variant draws a hairline. Use class to change the corner radius or make a square count.
Variants
Icon
icon takes a Svelte component and renders it before the text. The component receives size and class, so any icon component with those two props works. iconSize sets that size in pixels and defaults to 13. For anything else, such as a count, put it in children next to the text.
The example wraps a Hugeicons icon in a small component, pencil-icon.svelte:
<script lang="ts">
import { PencilEdit02Icon } from '@hugeicons/core-free-icons';
import HugeiconsIcon from '@mielui/svelte/hugeicons-icon';
let {
size = 13,
class: className
}: {
size?: number | string;
class?: string;
} = $props();
</script>
<HugeiconsIcon icon={PencilEdit02Icon} {size} class={className} />
API reference
Badge
Displays a compact status label.
variantBadgeVariantColor and emphasis. Status variants pair their color with your text.
Default
'secondary'iconComponent<{ size?: string | number | undefined; class?: string | undefined; }, {}, string>Icon component shown before the label.
iconSizestring | numberIcon size in pixels.
Default
13dotbooleanShows a small status dot before the label.
Default
falsechildrenSnippet<[]>Content rendered inside.
classstringClasses added to the element.
hrefstringRenders the badge as a link to this address.
pnpm dlx @mielui/svelte add badge