Skip to content

Layout

Avatar

Also calledprofile pictureuser pictureprofile image

A small image or initials representing a person or account, often shown beside a name.

How people describe it

  • “small round photo beside a persons name”
  • “circle with initials when there is no photo”
  • “little face picture next to a comment”

Good for

  • Comment authors
  • Account identity in a header

Don’t mix it up with

  • Shows a short status or count rather than a person or account.

What your library calls it

LIBRARYCALLS IT
shadcn/uiAvatar

Accessibility checklist

  • Avoid redundant image alt when a visible name is adjacent
  • Provide an accessible name for an avatar-only action
  • Do not use the photo alone to communicate status

Try it

MTOnline

Type a name to change the initials. Try the group view.

Prompt

Add an avatar with initials as a fallback and an accessible identity label.

~19 estimated prompt tokensDetailed: ~69 estimated prompt tokens

Rough estimate for prompt text only; actual counts vary by model and context.

"use client";
import { useState } from "react";

export function Avatar({ src, name, initials }: {
  src?: string;
  name: string;
  initials: string;
}) {
  const [failedSrc, setFailedSrc] = useState<string>();
  return (
    <span className="inline-flex items-center gap-2">
      {src && src !== failedSrc ? (
        <img src={src} alt="" width={44} height={44} onError={() => setFailedSrc(src)} className="size-11 rounded-full object-cover" />
      ) : (
        <span aria-hidden="true" className="grid size-11 shrink-0 place-items-center rounded-full border">{initials}</span>
      )}
      <span>{name}</span>
    </span>
  );
}

Used in

Explore website blueprints that use this component.