Usage
Src
Use the src prop to set the image URL. You can pass any property from HTML <img> element such as alt, loading, etc.
<template>
  <UAvatar src="https://github.com/benjamincanac.png" />
</template>
Size
Use the size prop to set the size of the Avatar.
<template>
  <UAvatar src="https://github.com/benjamincanac.png" size="xl" />
</template>
<img> element's width and height are automatically set based on the size prop.Icon
Use the icon prop to display a fallback Icon.
<template>
  <UAvatar icon="i-lucide-image" />
</template>
Text
Use the text prop to display a fallback text.
<template>
  <UAvatar text="+1" />
</template>
Alt
When no icon or text is provided, the initials of the alt prop is used as fallback.
<template>
  <UAvatar alt="Benjamin Canac" />
</template>
alt prop is passed to the img element as the alt attribute.Examples
With tooltip
You can use a Tooltip component to display a tooltip when hovering the Avatar.
<template>
  <UTooltip text="Benjamin Canac">
    <UAvatar
      src="https://github.com/benjamincanac.png"
      alt="Benjamin Canac"
    />
  </UTooltip>
</template>
With chip
You can use a Chip component to display a chip around the Avatar.
<template>
  <UChip inset>
    <UAvatar
      src="https://github.com/benjamincanac.png"
      alt="Benjamin Canac"
    />
  </UChip>
</template>
API
Props
| Prop | Default | Type | 
|---|---|---|
| as | 
 | 
 The element or component this component should render as. | 
| src | 
 | |
| alt | 
 | |
| icon | 
 | |
| text | 
 | |
| size | 
 | 
 | 
| delayMs | 
 Useful for delaying rendering so it only appears for those with slower connections. | |
| ui | 
 | 
Theme
export default defineAppConfig({
  ui: {
    avatar: {
      slots: {
        root: 'inline-flex items-center justify-center shrink-0 select-none overflow-hidden rounded-full align-middle bg-[var(--ui-bg-elevated)]',
        image: 'h-full w-full rounded-[inherit] object-cover',
        fallback: 'font-medium leading-none text-[var(--ui-text-muted)] truncate',
        icon: 'text-[var(--ui-text-muted)] shrink-0'
      },
      variants: {
        size: {
          '3xs': {
            root: 'size-4 text-[8px]'
          },
          '2xs': {
            root: 'size-5 text-[10px]'
          },
          xs: {
            root: 'size-6 text-xs'
          },
          sm: {
            root: 'size-7 text-sm'
          },
          md: {
            root: 'size-8 text-base'
          },
          lg: {
            root: 'size-9 text-lg'
          },
          xl: {
            root: 'size-10 text-xl'
          },
          '2xl': {
            root: 'size-11 text-[22px]'
          },
          '3xl': {
            root: 'size-12 text-2xl'
          }
        }
      },
      defaultVariants: {
        size: 'md'
      }
    }
  }
})
