Avatar

A round profile picture with an initials fallback.

Source
$npx @dinachi/cli@latest add avatar
RA
size
AvatarImage
AvatarFallback

Usage

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

export function UserAvatar() {
  return (
    <Avatar>
      <AvatarImage src="/avatars/jane.png" alt="Jane Doe" />
      <AvatarFallback>JD</AvatarFallback>
    </Avatar>
  )
}

Examples

RA
An image with initials as the fallback.
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';

export function Example() {
  return (
    <Avatar>
      <AvatarImage src="/avatar.png" alt="@raymond-ui" />
      <AvatarFallback>RA</AvatarFallback>
    </Avatar>
  );
}

Notes

Image optimizers

AvatarImage preloads src and renders once loaded, which breaks next/image and loading="lazy". Add keepMounted to render it at once; the fallback shows beneath until it loads, and stays if it fails.

import Image from "next/image"

<Avatar>
  <AvatarFallback>JD</AvatarFallback>
  <AvatarImage
    keepMounted
    render={<Image src="/avatars/jane.png" width={40} height={40} alt="Jane Doe" />}
  />
</Avatar>

API

size"sm" | "md" | "lg" = "md"
32, 40 or 48px square.
classNamestring
Merged over the size; your own width and height win.

Accessibility

  • Give AvatarImage an alt naming the person, or an empty alt when the name is beside it.
  • Fallback initials are read as letters. Prefer a visible name beside the avatar.