Examples
Image fallback, status, and group
Provide an accessible name, readable initials when no image is available, and text status for people who need it.
Avatar initials, status indicators, and grouped overflow
import { Avatar, AvatarGroup } from "@phuctech/ui/components/avatar";
const portrait = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Crect width='40' height='40' rx='20' fill='%237c3aed'/%3E%3C/svg%3E";
export function Example() {
return (
<div className="grid gap-5">
<div className="flex items-center gap-3">
<Avatar src={portrait} alt="Ava Nguyen" initials="AN" status="online" />
<Avatar alt="Minh Tran" initials="MT" status="away" />
<Avatar alt="An unavailable member" initials="AN" status="offline" />
</div>
<AvatarGroup label="Project members" max={3}>
<Avatar alt="Ava Nguyen" initials="AN" />
<Avatar alt="Minh Tran" initials="MT" />
<Avatar alt="Linh Pham" initials="LP" />
<Avatar alt="Quan Le" initials="QL" />
<Avatar alt="Mai Dao" initials="MD" />
</AvatarGroup>
</div>
);
}
Try the props
Compare size and the accessible status included in the avatar name.
Avatar property playground
import { Avatar } from "@phuctech/ui/components/avatar";
export function Example() {
return <Avatar alt="Ava Nguyen" initials="AN" size="md" status="online" />;
}When to use
Use Avatar to identify a person or named item in a list, card, or compact summary. The component renders a supplied image URL but does not fetch profile data. Provide initials or a useful fallback for image failures.
Usage
import { Avatar, AvatarGroup } from "@phuctech/ui/components/avatar";
<Avatar alt="Ava Nguyen" src={photoUrl} initials="AN" status="online" />
<AvatarGroup label="Project members" max={3}>{members}</AvatarGroup>API
Tokens
Accessibility
The root exposes the supplied alt text as its accessible name; a status is appended when present. The image itself is decorative to prevent duplicate announcements, and fallback text is hidden from assistive technology. AvatarGroup is a labeled group; overflow announces the number of additional people.
Do and don’t
Supply a meaningful name and a stable fallback for missing or failed images.
Use color-only status or rely on initials to distinguish people with the same name.