Keyboard shortcut: Ctrl + K
Get started

Badge

VBadge displays a count, icon or status dot, alone or attached to another element.

Usage

vue
8
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge :count="8" />
</template>

Examples

Variants

variant selects solid or soft. Dots are always solid.

vue
8888
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge :count="8" variant="solid" />
  <VBadge :count="8" variant="soft" />
  <VBadge :count="8" variant="solid" tone="danger" />
  <VBadge :count="8" variant="soft" tone="danger" />
</template>

Tones

tone sets the semantic colour.

vue
88888
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge :count="8" tone="accent" />
  <VBadge :count="8" tone="neutral" />
  <VBadge :count="8" tone="success" />
  <VBadge :count="8" tone="warning" />
  <VBadge :count="8" tone="danger" />
</template>

Custom colours

color overrides the tone with a CSS colour.

vue
8888
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge :count="8" color="#6d28d9" />
  <VBadge :count="8" color="teal" />
  <VBadge :count="8" color="oklch(0.72 0.19 60)" />
  <VBadge :count="8" color="#facc15" />
</template>

Counters

Counts above 99 appear as 99+.

vue
34299+
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge :count="3" />
  <VBadge :count="42" />
  <VBadge :count="128" />
</template>

With an icon

icon takes precedence over count.

vue
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
import { check, close, warning } from 'vectis-ui/icons'
</script>

<template>
  <VBadge :icon="check" tone="success" />
  <VBadge :icon="warning" tone="warning" />
  <VBadge :icon="close" tone="danger" />
</template>

Dot

dot shows a status dot and ignores count and icon content.

vue
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge dot />
  <VBadge dot tone="success" />
  <VBadge dot tone="danger" />
</template>

Inline

The default slot provides the target. Include the badge information in that target’s accessible name.

vue
MessagesDeployment
<script setup lang="ts">
import { VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge :count="4">Messages</VBadge>
  <VBadge dot tone="success">Deployment</VBadge>
</template>

Overlay

overlay places the badge at the target’s corner.

vue
<script setup lang="ts">
import { VAvatar, VBadge, VIconButton } from 'vectis-ui'
import { notifications } from 'vectis-ui/icons'
</script>

<template>
  <VBadge :count="12" overlay>
    <VIconButton label="Notifications" :icon="notifications" variant="ghost" tone="neutral" />
  </VBadge>

  <VBadge dot tone="success" overlay>
    <VAvatar name="Ada Lovelace" />
  </VBadge>
</template>

Overlay position

overlayPosition chooses the top or bottom corner. The horizontal side follows the reading direction.

vue
<script setup lang="ts">
import { VAvatar, VBadge } from 'vectis-ui'
</script>

<template>
  <VBadge :count="7" overlay>
    <VAvatar name="Ada Lovelace" size="lg" />
  </VBadge>

  <VBadge dot tone="success" overlay overlay-position="bottom">
    <VAvatar name="Grace Hopper" size="lg" />
  </VBadge>
</template>

Bordered

bordered adds a ring. Set ringColor to match the target’s surface.

vue
<script setup lang="ts">
import { VAvatar, VBadge } from 'vectis-ui'
</script>

<template>
  <div class="tile">
    <VBadge :count="3" overlay bordered ring-color="var(--vectis-color-surface-raised)">
      <VAvatar name="Ada Lovelace" />
    </VBadge>
  </div>

  <div class="tile tile-accent">
    <VBadge :count="3" tone="danger" overlay bordered ring-color="var(--vectis-color-accent)">
      <VAvatar name="Grace Hopper" />
    </VBadge>
  </div>
</template>

<style scoped>
.tile {
  display: flex;
  padding: var(--vectis-space-4);
  border-radius: var(--vectis-radius-surface);
  background: var(--vectis-color-surface-raised);
}
.tile-accent {
  background: var(--vectis-color-accent);
}
</style>

API

Props

PropTypeDefault
variantBadgeVariant'solid' | 'soft''solid'
Visual style.
toneBadgeTone'neutral' | 'accent' | 'danger' | 'success' | 'warning''accent'
Colour tone.
colorstringnone
Custom CSS colour. For solid badges, check foreground contrast in browsers without contrast-color() support.
countnumbernone
Count to display. Values above 99 appear as 99+.
iconIconSourcenone
Icon replacing the count.
dotbooleanfalse
Shows a status dot without content.
overlaybooleanfalse
Places the badge at the target’s corner. Requires a target in the default slot.
overlayPositionBadgeOverlayPosition'top' | 'bottom''top'
Top or bottom corner. The horizontal side follows the reading direction.
borderedbooleanfalse
Adds a ring around the badge.
ringColorstringnone
Ring colour when bordered. Defaults to the page background.

Slots

SlotType
default{}
Target element. Attached badges are hidden from assistive technology; include their information in the target’s accessible name.

Types

Types used in the API tables. Import exported types from vectis-ui.

export interface BuiltinIcon {
  name: string
  paths: readonly [string] | readonly [string, string]
}
export type IconRender =
  | { path: string; viewBox?: string }
  | { component: Component; props?: Record<string, unknown> }
  | { src: string }
  | { text: string; class?: string }
  | { class: string }
export type IconSource = string | BuiltinIcon | IconRender

CSS variables

TokenValue
--vectis-control-size-badge-h1.25rem
--vectis-control-size-badge-dot0.625rem
--vectis-control-size-badge-ring2px