Avatar

A circular identity for a person. A photo when there is one, otherwise initials, otherwise an icon. Agents are shown with the mascot, not an avatar.

Usage

pnpm dlx shadcn@latest add avatar

Then replace components/ui/avatar.tsx with the Matrix version. It keeps shadcn's parts and adds sizes, initials from a name and the icon fallback.

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

// Pass a name: it becomes the label screen readers announce and the fallback initials.
<Avatar name="Maya Lindqvist">
  <AvatarImage src={user.photoUrl} alt="" />
  <AvatarFallback />
</Avatar>

Default

PhotoThe person's own image

The default is the person's photo. Always include AvatarFallback too: it shows the initials while the photo loads and whenever there isn't one (see Fallback). Avatars are for people. Agents aren't avatars: they're shown with the Matrix mascot, a separate component.

Sizes

20 · 24 · 32 · 40
xs 20sm 24md 32lg 40

md (32px) is the default size. When there's no photo, initials are 40% of the circle and icons use the matching Iconography size, so both scale with the avatar.

Fallback

Photo → initials → icon
PhotoInitialsIcon

Indicator

A dot on the edge

The dot is green (bg-success) by default; pass any status color with className. Its size follows the avatar. A dot alone doesn't say what it means, so pair it with text nearby ("Online", "Away").

As a button

Open a profile or menu

Wrap the avatar in a real button with an aria-label. The gold focus ring comes from the theme; tab to the example to see it.

Group

A few avatars and a +N chip
+4
+2

Every avatar in a group shares one size; give AvatarGroupCount the same size. Each avatar gets a ring in the page color so the overlap reads clearly.

Loading

Skeleton circle

Behavior

The fallback is a cascade

The image loads over the fallback. While it loads, or if the address is broken, people see initials, never an empty circle that later jumps.

Initials stop at two

First word plus last word: "Mary Jane Watson" is MW. Emoji and accented letters are never cut in half. Use getInitials(name) if you need the same letters elsewhere.

The name is the label

With name, screen readers announce "Maya Lindqvist", not "O R". Without a name (the icon fallback), add role="img" and an aria-label.

API reference

Prop

Type

AvatarImage takes the usual src and alt (keep alt="" when name is set). AvatarFallback shows its children if you pass them, otherwise the initials, otherwise the icon. AvatarBadge and AvatarGroupCount take className; AvatarGroupCount and AvatarSkeleton also take size.

Guidelines

  • Always pass a name. Different initials make a list read as different people instead of a wall of identical icons.
  • Use avatars for people only. Agents are shown with the mascot.
  • Use xs (20px) in menus and dense lists, md or lg in rows, cards and chat.
  • For several people, use a group with a few avatars and a +N chip, never one avatar and a number.
  • Don't rely on the indicator color alone; say what it means in text nearby.
  • Don't make avatars square or give them other colors; one consistent circle keeps people recognisable everywhere.