---
title: "Badge"
description: "A compact label for status, counts, or categories."
category: "Display & Misc"
slug: badge
url: /components/badge
since: "0.2.0"
status: "stable"
---

# Badge

A compact label for status, counts, or categories.

## Import

```svelte
import { Badge } from '@elluzion/iv-ui';
```

## Preview

Neutral, success, error, accent, and info.

```svelte
<script lang="ts">
	import { Badge } from '@elluzion/iv-ui';
</script>

<div class="row">
	<Badge>neutral</Badge>
	<Badge variant="success">success</Badge>
	<Badge variant="error">error</Badge>
	<Badge variant="accent">accent</Badge>
	<Badge variant="info">info</Badge>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}
</style>
```

## Usage

- `variant` colors the label; `neutral` stays monochrome.
- `dismissible` adds a remove button wired to `ondismiss`.
- Badges are not buttons; use `Toggle` for pressable chips.

## Examples

### Sizes

`sm` and `md` label heights.

```svelte
<script lang="ts">
	import { Badge } from '@elluzion/iv-ui';
</script>

<div class="row">
	<Badge size="sm" variant="success">stable</Badge>
	<Badge variant="success">stable</Badge>
	<Badge size="sm" variant="accent">beta</Badge>
	<Badge variant="accent">beta</Badge>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}
</style>
```

### Dismissible

A trailing remove button calls `ondismiss`.

```svelte
<script lang="ts">
	import { Badge, Button } from '@elluzion/iv-ui';

	let tags = $state(['edge', 'cache', 'read-only']);

	function remove(tag: string) {
		tags = tags.filter((value) => value !== tag);
	}
</script>

<div class="stack">
	<div class="row">
		{#each tags as tag (tag)}
			<Badge variant="neutral" dismissible ondismiss={() => remove(tag)}>{tag}</Badge>
		{/each}
		{#if tags.length === 0}<span class="empty">no tags</span>{/if}
	</div>
	{#if tags.length < 3}
		<Button size="sm" variant="ghost" onclick={() => (tags = ['edge', 'cache', 'read-only'])}>
			Restore
		</Button>
	{/if}
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		align-items: start;
		gap: var(--iv_spacing-sm);
	}

	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}

	.empty {
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>
```

### Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `'neutral' \| 'success' \| 'error' \| 'accent' \| 'info'` | `'neutral'` | Status color. `neutral` is the default. |
| `size` | `'sm' \| 'md'` | `'md'` | Badge size. |
| `dismissible` | `boolean` | `false` | Shows a remove button. |
| `className` | `string` | `''` | Extra classes merged onto the root element. |

### Events

| Event | Handler type | Description |
| --- | --- | --- |
| `dismiss` | `() => void` | Called when the remove button is pressed. |

The legacy `on:name` form is accepted for every event.

### Snippets

| Snippet | Type | Description |
| --- | --- | --- |
| `children` | `Snippet` | Badge text. |

### Tokens used

`--iv_accent` · `--iv_badge-h-md` · `--iv_badge-h-sm` · `--iv_badge-pad-x-md` · `--iv_badge-pad-x-sm` · `--iv_border` · `--iv_error` · `--iv_font-mono` · `--iv_foreground` · `--iv_foreground-dim` · `--iv_info` · `--iv_outline-offset` · `--iv_outline-width` · `--iv_radius-sm` · `--iv_spacing-sm` · `--iv_spacing-xs` · `--iv_success` · `--iv_surface-elevated` · `--iv_surface-overlay` · `--iv_text-chips` · `--iv_text-xs` · `--iv_weight-semibold`

See the [token reference](/foundations/tokens.md) for values.

### CSS hooks

`.iv-accent` · `.iv-badge` · `.iv-badge-content` · `.iv-badge-dismiss` · `.iv-dismissible` · `.iv-error` · `.iv-info` · `.iv-sm` · `.iv-success`

## Accessibility

- Color is not the only signal; the text carries the meaning.
- The dismiss control is a button with an accessible name.
- Keep labels short; the badge truncates instead of wrapping.

## Related

- [Avatar](/components/avatar.md)
- [Alert](/components/alert.md)
- [Shortcut](/components/shortcut.md)
- [Card](/components/card.md)