Data Display

Badge

Display short labels, statuses, or counts. Badges support multiple variants, colors, sizes, icons, and avatars for flexible inline indicators.

Playground

Experiment with different props in real-time.

Badge

Basic Usage

Import and use the Badge component with a label prop.

Badge
<script lang="ts">
  import { Badge } from 'sv5ui';
</script>

<Badge label="Badge" />

Variants

4 visual styles for different levels of emphasis.

Solid Soft Outline Subtle
<Badge variant="solid" label="Solid" />
<Badge variant="soft" label="Soft" />
<Badge variant="outline" label="Outline" />
<Badge variant="subtle" label="Subtle" />

Sizes

5 sizes from extra small to extra large.

Extra Small Small Medium Large Extra Large
<Badge size="xs" label="Extra Small" />
<Badge size="sm" label="Small" />
<Badge size="md" label="Medium" />
<Badge size="lg" label="Large" />
<Badge size="xl" label="Extra Large" />

Colors

8 semantic color schemes.

Primary Secondary Tertiary Success Warning Error Info Surface
<Badge color="primary" label="Primary" />
<Badge color="secondary" label="Secondary" />
<Badge color="tertiary" label="Tertiary" />
<Badge color="success" label="Success" />
<Badge color="warning" label="Warning" />
<Badge color="error" label="Error" />
<Badge color="info" label="Info" />
<Badge color="surface" label="Surface" />

With Icons

Add icons in various positions using Iconify names.

Featured Next Verified
<!-- Icon only -->
<Badge icon="lucide:check" />

<!-- Leading icon -->
<Badge leadingIcon="lucide:star" label="Featured" />

<!-- Trailing icon -->
<Badge trailingIcon="lucide:arrow-right" label="Next" />

<!-- Both icons -->
<Badge leadingIcon="lucide:circle-check" trailingIcon="lucide:x" label="Verified" />

With Avatar

Display an avatar alongside the badge label using the avatar prop.

JD
John Doe
JS
Jane Smith
<Badge
  label="John Doe"
  avatar={{ src: 'https://i.pravatar.cc/40?img=1', alt: 'John Doe' }}
/>
<Badge
  label="Jane Smith"
  avatar={{ src: 'https://i.pravatar.cc/40?img=5', alt: 'Jane Smith' }}
  color="secondary"
/>

Square Badge

Use the square prop for equal width and height, ideal for counts or single icons.

5 99
<Badge icon="lucide:plus" square />
<Badge label="5" square />
<Badge label="99" square color="error" />

UI Slots

Use the ui prop to override classes on specific internal elements of the Badge.

SlotDescription
baseRoot badge element — controls shape, padding, shadow, etc.
labelText label wrapper — controls font, spacing, text styles
leadingIconIcon before the label — controls icon size, color
trailingIconIcon after the label — controls icon size, color
leadingAvatarAvatar before the label — controls avatar wrapper styles
leadingAvatarSizeAvatar size override within the badge
Custom Styled
<Badge
  label="Custom Styled"
  leadingIcon="lucide:star"
  ui={{
    base: 'rounded-full shadow-lg',
    label: 'font-bold tracking-wide',
    leadingIcon: 'text-yellow-400'
  }}
/>

Snippets

Use snippets to fully replace the leading or trailing content with custom markup.

SnippetReplacesDescription
childrenlabelDefault slot for custom label content
leadingleadingIcon / avatarCustom content before the label — replaces icon and avatar
trailingtrailingIconCustom content after the label — replaces trailing icon
AI
v4
<Badge variant="outline" color="primary">
  {#snippet leading()}
    <div class="flex h-4 w-4 items-center justify-center rounded-full bg-primary">
      <span class="text-[8px] font-bold text-on-primary">AI</span>
    </div>
  {/snippet}
  Claude
  {#snippet trailing()}
    <span class="text-[10px] opacity-60">v4</span>
  {/snippet}
</Badge>

Props

PropTypeDefault
askeyof HTMLElementTagNameMap'span'
labelstring | number-
color'primary' | 'secondary' | 'tertiary' | 'success' | 'warning' | 'error' | 'info' | 'surface''primary'
variant'solid' | 'soft' | 'outline' | 'subtle''solid'
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
squarebooleanfalse
iconstring-
leadingIconstring-
trailingIconstring-
avatarAvatarProps-
classstring-
uiRecord<Slot, Class>-