Skip to content

Avatar

Image with graceful fallback (initials, icon, or arbitrary slot). Built on Reka UI's AvatarRoot + AvatarImage + AvatarFallback. Reka handles the load-state dance — the fallback renders if the image is missing, fails, or is still loading.

bash
npm install @vuecs/elements
vue
<script setup lang="ts">
import { VCAvatar } from '@vuecs/elements';
</script>

<template>
    <VCAvatar src="https://i.pravatar.cc/80?img=15" alt="User" />

    <!-- Image fails → fallback wins -->
    <VCAvatar src="https://invalid.example.com/x.jpg" alt="Broken">
        <template #fallback>AB</template>
    </VCAvatar>

    <!-- No src → fallback renders immediately -->
    <VCAvatar>
        <template #fallback>?</template>
    </VCAvatar>
</template>
css
@import "tailwindcss";
@import "@vuecs/design";
@import "@vuecs/elements";

@custom-variant dark (&:where(.dark, .dark *));

Props

PropTypeDefaultDescription
srcstringundefinedImage source. When omitted, the fallback renders immediately.
altstring''Alt text for the image. Empty string = decorative; pass a meaningful value when the avatar conveys identity.
delayMsnumberundefinedDelay before the fallback appears — useful to avoid a flicker on fast connections. Only strictly positive values are forwarded to Reka (its AvatarFallback treats 0 as "wait forever"); omit to render the fallback immediately.
size'sm' | 'md' | 'lg'theme default (md)Size variant. sm ≈ 32px, md ≈ 40px, lg ≈ 56px (theme-defined). For arbitrary pixel sizes, use :theme-class="{ root: extend('h-12 w-12') }" instead. Mirrors <VCBadge>'s size axis.
themeClassPartial<AvatarThemeClasses>undefinedPer-instance theme override.
themeVariantRecord<string, string | boolean>undefinedPer-instance variant values.

Slots

SlotPropsDescription
fallback{ class }Rendered when the image is absent or failed. Default: empty string.

Theme keys

KeyDefault classNotes
rootvc-avatarOuter wrapper.
imagevc-avatar-imageThe <img> element.
fallbackvc-avatar-fallbackFallback wrapper.

Released under the Apache 2.0 License.