Veil UI
Components

Avatar

An image representing a user, with an initials fallback.

Installation

$ npx veil-ui@latest add avatar

Usage

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";

<Avatar>
  <AvatarImage src="/ada.png" alt="Ada Lovelace" />
  <AvatarFallback>AL</AvatarFallback>
</Avatar>;

Examples

Basic

AL

Sizes

SMMDLG

Fallback

GH

Grace Hopper

grace@veil.dev

Radix renders the fallback while the image loads and whenever it fails.

Group

ALGHATKJ+4

API reference

PropTypeDefaultDescription
size"sm" | "default" | "lg""default"Diameter of the avatar.
src / altstring—Passed to AvatarImage; alt is required for meaningful images.

Accessibility

  • Always provide alt on AvatarImage. Use an empty alt only when the avatar is decorative and the name appears next to it.
  • The fallback is plain text inside the avatar, so it is announced when the image is unavailable.
  • In a group, add an accessible label such as aria-label="4 teammates" to the wrapping element.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add avatar --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { AvatarRoot } from "reka-ui";
import { computed } from "vue";

import { cn } from "@/lib/utils";

import { avatarVariants, type AvatarVariants } from "./variants";

const props = defineProps<{
  class?: string;
  size?: AvatarVariants["size"];
}>();

const classes = computed(() =>
  cn(avatarVariants({ size: props.size }), props.class),
);
</script>

<template>
  <AvatarRoot
    data-slot="avatar"
    :data-size="size ?? 'default'"
    :class="classes"
  >
    <slot />
  </AvatarRoot>
</template>

On this page