Avatar
A profile picture with initials or an icon as its fallback.
Usage guidelines
- Name a standalone avatar: Give
Avatarrole="img"and the person's full name througharia-label, and giveAvatarImagean emptyalt. 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"onAvatarso the name is not announced twice. - Supply the fallback content:
Avatardoes not derive initials from a name. Pass initials or an icon toAvatarFallback, and put a custom background color onAvatarFallback, not on the root, so transparent images keep their transparency. - Set the size on the root:
sizeonAvatarsizes the image and the fallback text together, fromxxs(16px) to3xl(64px). The default ismd(32px). - Compute overflow yourself:
AvatarGrouponly overlaps its children and shares a size. The caller picks which avatars to show, renders the+Ncount inAvatarGroupCount, and names that count.
Anatomy
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.
Image fallback
The fallback shows while the image loads and stays when it fails. Use an icon when there are no initials to show.
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.
Beside a name
In a member list the visible name identifies the person, so the avatar is hidden from assistive technology.
- Evan Chenevan@example.comOwner
- Sofia Rossisofia@example.comEditor
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.
| Prop | Type | Default | Details |
|---|---|---|---|
size | '2xl' | '3xl' | 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xxs' | 'md' | |
className | string | ((state: AvatarRootState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, AvatarRootState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: AvatarRootState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-imageloadingstatus | Values: The image loading status. |
| Variable | Description |
|---|---|
--avatar-size | Values: The avatar diameter. The |
--avatar-font-size | Values: The font size of the fallback initials, set together with |
AvatarFallback
Rendered when the image fails to load or when no image is provided. Renders a <span> element.
| Prop | Type | Default | Details |
|---|---|---|---|
delay | number | 0 | |
className | string | ((state: AvatarFallbackState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, AvatarFallbackState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: AvatarFallbackState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-imageloadingstatus | Values: 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.
| Prop | Type | Default | Details |
|---|---|---|---|
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.
| Prop | Type | Default | Details |
|---|---|---|---|
size | '2xl' | '3xl' | 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xxs' | 'md' | |
AvatarImage
The image to be displayed in the avatar. Renders an <img> element.
| Prop | Type | Default | Details |
|---|---|---|---|
onLoadingStatusChange | ((status: ImageLoadingStatus) => void) | No default | |
keepMounted | boolean | false | |
className | string | ((state: AvatarImageState) => string | undefined) | No default | |
render | ComponentRenderFn<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, AvatarImageState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: AvatarImageState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
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. |