Skip to content

Avatar

A profile picture with initials or an icon as its fallback.

ECSRRTMJ+3
hero.tsx

Usage guidelines

  • Name a standalone avatar: Give Avatar role="img" and the person's full name through aria-label, and give AvatarImage an empty alt. The name stays stable while the image loads or after it fails.
  • Hide an avatar next to its name: When adjacent text or the surrounding control already identifies the person, set aria-hidden="true" on Avatar so the name is not announced twice.
  • Supply the fallback content: Avatar does not derive initials from a name. Pass initials or an icon to AvatarFallback, and put a custom background color on AvatarFallback, not on the root, so transparent images keep their transparency.
  • Set the size on the root: size on Avatar sizes the image and the fallback text together, from xxs (16px) to 3xl (64px). The default is md (32px).
  • Compute overflow yourself: AvatarGroup only overlaps its children and shares a size. The caller picks which avatars to show, renders the +N count in AvatarGroupCount, and names that count.

Anatomy

tsx
tsx

Place AvatarFallback before AvatarImage. AvatarGroup and AvatarGroupCount are Dify additions and render plain <span> elements.

Examples

Sizes

Eight sizes cover dense table rows to profile headers. The fallback text scales with the avatar.

ECxxs
ECxs
ECsm
ECmd
EClg
ECxl
EC2xl
EC3xl
sizes.tsx

Image fallback

The fallback shows while the image loads and stays when it fails. Use an icon when there are no initials to show.

NKBroken image
Icon fallback
image-fallback.tsx

Group

AvatarGroup overlaps its children from the inline start and passes its size to them; an explicit size on a child wins. Put AvatarGroupCount last so it sits behind the avatars. When a visible label describes the group, give it role="group" and point aria-labelledby at the label.

EditorsECSRRT+2
group.tsx

Beside a name

In a member list the visible name identifies the person, so the avatar is hidden from assistive technology.

  • Evan Chenevan@example.com
    Owner
  • Sofia Rossisofia@example.com
    Editor
decorative.tsx

API reference

Avatar

Displays a user's profile picture, initials, or fallback icon. Renders a <span> element.

Set role="img" and aria-label with an empty image alt for standalone identities, or aria-hidden="true" when adjacent text already names the person.

Base UI Avatar.Root docs

Props
PropTypeDefaultDetails
size'2xl' | '3xl' | 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xxs''md'
Base UI Avatar.Root docs
Data attributes
AttributeDescription
data-imageloadingstatus

Values: 'error' | 'idle' | 'loaded' | 'loading'

The image loading status.

CSS variables
VariableDescription
--avatar-size

Values: length

The avatar diameter. The size prop sets it; override it for a size outside the scale.

--avatar-font-size

Values: length

The font size of the fallback initials, set together with --avatar-size.

AvatarFallback

Rendered when the image fails to load or when no image is provided. Renders a <span> element.

Base UI Avatar.Fallback docs

Data attributes
AttributeDescription
data-imageloadingstatus

Values: 'error' | 'idle' | 'loaded' | 'loading'

The image loading status.

AvatarGroup

Overlaps a row of avatars and sets their default size; an explicit size on a child wins. Renders a <span> element.

Props
PropTypeDefaultDetails
size'2xl' | '3xl' | 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xxs''md'

AvatarGroupCount

Displays caller-provided overflow text such as +2 alongside an AvatarGroup. Renders a <span> element.

Props
PropTypeDefaultDetails
size'2xl' | '3xl' | 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xxs''md'

AvatarImage

The image to be displayed in the avatar. Renders an <img> element.

Base UI Avatar.Image docs

Data attributes
AttributeDescription
data-loading

Present while the image is loading.

data-error

Present when the image failed to load.

data-starting-style

Present when the image begins animating in.

data-ending-style

Present when the image is animating out.