Avatar
A person's picture, initials or a generic icon. Seven sizes, circle or square, and avatar groups.
Version 0.2.0 ·
Installation
bunx --bun shadcn@latest add @dga/avatarUsage
import { Avatar, AvatarGroup } from "@/components/ui/avatar";
<Avatar src="/people/noura.jpg" alt="نورة القحطاني" initials="ن ق" />
<AvatarGroup>
<Avatar size={32} src="/people/noura.jpg" alt="نورة" />
<Avatar size={32} initials="+3" aria-label="3 أشخاص آخرون" />
</AvatarGroup>Built on the Base UI Avatar, which shows the fallback while the image loads and if it fails.
Anatomy
- Avatar: the root, with the image or the fallback.
- Image: the picture.
- Fallback: initials, or a generic user icon.
- AvatarGroup: a row of avatars, stacked or spaced.
Examples
Sizes and shape
24, 32, 40 (default), 48, 64, 80 and 120px. square uses radius-md; bordered adds a white ring.
Groups
AvatarGroup overlaps its children by 4px with a white ring (stacked, the default). Set stacked={false} to space them.
RTL
A group stacks from the start side, so the overlap direction flips in Arabic.
Accessibility
- Give the image an
altwith the person's name, unless the name is already shown next to it (then usealt=""). - Initials are read as text. For a "+3" overflow avatar, add an
aria-labelsuch as "3 more people". - The fallback icon is hidden from screen readers.
API Reference
Avatar
A person's picture, initials or a generic user icon.
| Prop | Type | Default |
|---|---|---|
24 | 32 | 40 | 48 | 64 | 80 | 120Size in pixels. | 40 | |
| ||
booleanSquare with rounded corners instead of a circle. | false | |
| ||
booleanAdds a ring around the avatar. | false | |
| ||
stringOne or two letters shown when there is no image. | No default | |
| ||
stringImage URL. Falls back to the initials or icon if it is missing or fails to load. | No default | |
| ||
stringAlternative text for the image. Use the person's name. | "" | |
| ||
Also accepts every prop of the Base UI Avatar (opens in a new tab).
AvatarGroup
A row of avatars. Put an Avatar with initials like "+3" last for the remainder.
| Prop | Type | Default |
|---|---|---|
booleanOverlap the avatars (Figma: Stacked). | true | |
| ||
Also accepts every prop of the Base UI Avatar (opens in a new tab).
Deviations from DGA
| Change | Reason |
|---|---|
Avatar: sizes and text | One text size cannot fit avatars from 24 to 120px. |
Contrast
12 pairs checked · all pass WCAG 2.1 AAShow 2 statesHide
| Variant / state | Light | Dark |
|---|---|---|
| initials / text | 16.44:1 AAA | 12.71:1 AAA |
| icon / icon | 16.44:1 3:1 | 12.71:1 3:1 |
Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report