Keyboard shortcut: Ctrl + K
Get started

Avatar

VAvatar represents a person or entity with an image, icon or initials.

Usage

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

<template>
  <VAvatar name="Ada Lovelace" />
</template>

Examples

With a picture

src displays the image. If it fails to load, the avatar uses its icon or initials.

vue
Anna Fisher
<script setup lang="ts">
import { VAvatar } from 'vectis-ui'

import portrait from '~/assets/img/anna-fisher.jpg'
</script>

<template>
  <VAvatar :src="portrait" name="Anna Fisher" size="lg" />
</template>

With an icon

icon replaces initials. Provide name or alt for an accessible name.

vue
<script setup lang="ts">
import { VAvatar } from 'vectis-ui'
import { code, notifications, table_chart as tableChart } from 'vectis-ui/icons'
</script>

<template>
  <VAvatar :icon="code" alt="Build bot" />
  <VAvatar :icon="notifications" alt="System alerts" />
  <VAvatar :icon="tableChart" alt="Nightly report" />
</template>

Initials and automatic colour

Without an image or icon, name supplies initials and determines the background colour.

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

<template>
  <VAvatar name="Ada Lovelace" />
  <VAvatar name="Grace Hopper" />
  <VAvatar name="Alan Turing" />
</template>

Sizes

size sets the avatar diameter.

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

<template>
  <VAvatar name="Ada Lovelace" size="xs" />
  <VAvatar name="Ada Lovelace" size="sm" />
  <VAvatar name="Ada Lovelace" size="md" />
  <VAvatar name="Ada Lovelace" size="lg" />
  <VAvatar name="Ada Lovelace" size="xl" />
</template>

Custom colour

color overrides the automatic background. Check its contrast with the white foreground.

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

<template>
  <VAvatar name="Vectis UI" color="#6d28d9" />
  <VAvatar name="Atlas" color="teal" />
  <VAvatar name="Meridian" color="oklch(0.55 0.18 25)" />
</template>

clickable creates a button; href creates a link and takes precedence. disabled disables either control.

vue

Profile opened 0 times

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

const opened = ref(0)
</script>

<template>
  <VAvatar name="Ada Lovelace" clickable @click="opened += 1" />
  <VAvatar name="Grace Hopper" href="#usage" />
  <VAvatar name="Alan Turing" href="#usage" disabled />
  <VTypography variant="body-sm" tone="muted">Profile opened {{ opened }} times</VTypography>
</template>

With a tooltip

For VTooltip, make the avatar focusable with clickable or href and bind triggerProps.

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

<template>
  <VTooltip text="Ada Lovelace, on call until Friday">
    <template #default="{ triggerProps }">
      <VAvatar name="Ada Lovelace" clickable v-bind="triggerProps" />
    </template>
  </VTooltip>
</template>

Router

VAvatar renders a real <a> when href is set. With Nuxt or Vue Router, render it inside the router link in custom mode and pass on href and navigate. A click with a modifier key still opens a new tab.

vue
<RouterLink v-slot="{ href, navigate }" to="/profile" custom>
  <VAvatar :href="href" name="Ada Lovelace" @click="navigate" />
</RouterLink>

API

Props

PropTypeDefault
srcstringnone
Image URL. Falls back to the icon or initials on loading failure.
iconIconSourcenone
Icon shown without an image. Takes precedence over initials.
namestringnone
Full name used for the accessible name, initials and automatic colour.
altstringnone
Accessible name overriding name. Consumer aria-label takes precedence.
colorstringnone
Custom CSS background colour. The foreground stays white.
sizeAvatarSize'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
Avatar diameter. Inherits the group size; otherwise defaults to md.
hrefstringnone
Link destination. Takes precedence over clickable; removed when disabled.
clickablebooleanfalse
Renders a button when href is absent.
disabledbooleanfalse
Disables interactive avatars and removes them from the tab order.

Slots

SlotType
default{}
Content replacing initials.

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-avatar-ring2px