Skip to main content

Overview

Avatar provides a robust image display system with automatic fallback logic. It uses an internal selection system with mandatory: 'force' to ensure one item is always visible. Images register with priority values and the highest-priority loaded image is displayed.

Sub-Components

  • Avatar.Root: Container that manages image loading state and fallback logic
  • Avatar.Image: Image component with automatic show/hide based on load state
  • Avatar.Fallback: Fallback content shown when no images are loaded

Usage

<script lang="ts" setup>
import { Avatar } from '@vuetify/v0'
</script>

<template>
  <Avatar.Root>
    <Avatar.Image src="/avatar.jpg" />
    <Avatar.Fallback>JD</Avatar.Fallback>
  </Avatar.Root>
</template>

Avatar.Root

Props

as
DOMElement | null
default:"'div'"
The HTML element to render as
renderless
boolean
default:"false"
Render without a wrapper element
namespace
string
default:"'v0:avatar'"
Namespace for dependency injection

Slots

default
Content slot for Avatar.Image and Avatar.Fallback components

Avatar.Image

Props

as
DOMElement | null
default:"'img'"
The HTML element to render as
src
string
Image source URL
priority
number
default:"0"
Priority for display order (higher = more preferred)
namespace
string
default:"'v0:avatar'"
Namespace for retrieving avatar context

Events

load
(e: Event) => void
Emitted when image successfully loads
error
(e: Event) => void
Emitted when image fails to load

Slot Props

isSelected
boolean
Whether this image is currently visible
attrs
object
Attributes to bind to the image element including role, src, onLoad, and onError

Avatar.Fallback

Props

as
DOMElement | null
default:"'span'"
The HTML element to render as
namespace
string
default:"'v0:avatar'"
Namespace for retrieving avatar context

Slot Props

isSelected
boolean
Whether this fallback is currently visible

Examples

<script setup>
import { Avatar } from '@vuetify/v0'
</script>

<template>
  <Avatar.Root>
    <Avatar.Image src="/avatar.jpg" />
    <Avatar.Fallback>JD</Avatar.Fallback>
  </Avatar.Root>
</template>

Accessibility

Avatar.Image automatically sets role="img" for accessibility:
<template>
  <Avatar.Root>
    <Avatar.Image src="/avatar.jpg" alt="User avatar" />
    <Avatar.Fallback>JD</Avatar.Fallback>
  </Avatar.Root>
</template>

SSR

Avatar is fully compatible with SSR. On the server, the fallback will be rendered by default since images cannot load:
<template>
  <Avatar.Root>
    <Avatar.Image src="/avatar.jpg" />
    <Avatar.Fallback>JD</Avatar.Fallback>
  </Avatar.Root>
</template>

Build docs developers (and LLMs) love