Avatar
StableA compact visual identity for a person or an organization, with an image, initials fallback and optional presence status.
Anatomy
- 1RootA circle for people, a rounded square for organizations. Five sizes, from 20 to 56px.
- 2BadgeAn optional status dot, ringed in the page color so it separates from the image.
- 3FallbackInitials on a neutral fill, shown while the image loads — or instead of it, when there is none.
- 4GroupOverlapping avatars, each ringed in the page color.
- 5CountHow many more people there are, sized to match the group.
Installation
$ pnpm dlx shadcn@latest add https://www.prfct.dev/r/avatar.jsonUsage
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"<Avatar>
<AvatarImage src="/avatars/maya.png" alt="Maya Chen" />
<AvatarFallback>MC</AvatarFallback>
</Avatar>Always include an AvatarFallback. It renders while the image loads and permanently when the image is missing or fails, so a slow network or a deleted file never leaves a hole in the layout.
Examples
Sizes
Five sizes follow the control scale: xs 20, sm 24, default 32, lg 40 and xl 56 pixels. Initials scale with the avatar so they stay optically centered.
Fallback
When there is no image, show two uppercase initials — given name and family name. For people you know nothing about, use a neutral icon and give it an accessible name.
delay={600} to AvatarFallback to show it only when loading is genuinely slow.Shape
Circles are for people; rounded squares are for things people belong to — workspaces, organizations, apps. The shape carries meaning, so keep it consistent across the product.
Status
AvatarBadge sits on the bottom-right edge with a ring in the page color, so it reads on any background. It defaults to the success color for online; recolor it with a semantic token for other states, and always include a text label for screen readers.
Group
Stack avatars to show who is involved without listing everyone. Show three to five, then summarize the rest with AvatarGroupCount. Each avatar gets a ring in the page color so overlaps stay crisp.
With text
Most of the time an avatar sits next to a name. Because the name is already visible, the avatar is decorative: give the image an empty alt so assistive technology doesn't announce the name twice.
Guidelines
When to use
- To help people recognize who did something: comment authors, assignees, collaborators, account owners.
- To identify a workspace, organization or connected app in switchers and lists.
When not to use
- For decorative or editorial imagery — use a regular image.
- For objects that aren't people or organizations, such as files or integrations in a list — use Item with an icon.
- As the only way to identify someone in a dense table. Pair it with a name, or make the name available in a tooltip.
Consistent identity
Initials
Images
- Use a square source at least twice the rendered size (112px for
xl) so avatars stay sharp on high-density screens. - Crop around the face or logo; the avatar applies
object-coverand clips to its shape. - Don't add borders — every avatar already has a hairline inner ring that keeps light images from dissolving into light surfaces.
Accessibility
- Name the image.
AvatarImagerenders an<img>: setaltto the person's or organization's name. When the name is visible next to the avatar, setalt=""and addaria-hiddento theAvatarso the initials aren't announced as letters. - Status needs words. The badge is color and position only. Put a visually hidden label inside it (
<span className="sr-only">Online</span>), and show presence as text wherever it matters. - Groups need a summary. Give
AvatarGroupanaria-labelthat lists the people or states how many there are — "Project members: Maya Chen, Jonah Okafor and 12 others". - Contrast. Fallback initials (
gray-11ongray-4) meet 4.5:1 in both modes.
API reference
Avatar
The root. Accepts every prop of the Base UI Avatar Root.
AvatarImage
AvatarFallback
AvatarBadge
A <span> positioned on the avatar's edge. Defaults to the success color; override with a background token such as bg-warning-9. Icons inside are sized for you.
AvatarGroup
A <div> that overlaps its avatars and rings them in the page color. Accepts all div props, including aria-label.
AvatarGroupCount
A <div> for the "+N" summary at the end of a group. It follows the size of the avatars in the group automatically.