Skip to content

Avatar

An image element with a fallback for when the image fails to load.

Avatar displays an image and falls back to initials or an icon while loading or after an error.

Anatomy

  • #image: The <img> element or full image replacement.
  • #fallback: Content shown while the image is delayed, loading, or failed.

Usage

AL BK

Examples

Custom fallback

Use #fallback to render initials or an icon with your own styles.

vue
@layer akaza-reset;
@import "tailwindcss";
@import "akaza-ui/dist/akaza-ui.css";

Delayed fallback

Prevent a flash of the fallback during fast loads.

vue
<template>
  <Avatar
    src="/avatar.jpg"
    alt="Jane Doe"
    text="JD"
    :delay-ms="300"
  />
</template>

Custom image element

Use #image to render a custom element instead of a plain <img>.

vue
<Button
  :ui="{
    root: 'rounded-md bg-black px-3 py-2 text-white',
    spinner: 'size-4 animate-spin',
  }"
>
  Save
</Button>

API Reference

Props

PropTypeDefaultDescription
srcstring—Image URL.
altstring""Alt text for the image.
textstring—Fallback text (e.g. initials) when no #fallback slot is provided.
delayMsnumber0Delay in ms before showing the fallback. Prevents flash on fast loads.
asstring"span"Root element tag.
uiAvatarUi—CSS class overrides.

Slots

SlotScoped propsDescription
image{ src, alt, status }The image element.
fallback{ status }Shown when image is unavailable or loading.

status is one of: "idle" · "loading" · "loaded" · "error"

Emits

EventPayloadDescription
status-change[status: AvatarImageStatus]Fired when image loading status changes.

UI Options

KeyDescription
rootThe outer container element.
imageThe image element.
fallbackThe fallback element.

Styling Hooks

UI keyCSS classData attrs
rootakaza-avatardata-akaza-status
imageakaza-avatar-image—
fallbackakaza-avatar-fallbackdata-akaza-status
Edit this page on GitHub ↗