Avatar
An image element with a fallback for representing the user.
When to Use
Use Avatar when you need to:
- Represent a user or entity with a profile photo or initials
- Display user identity in navigation bars, comments, or chat interfaces
- Show a group of collaborators or team members with stacked avatars
- Provide a visual indicator for account menus or user settings
- Accompany user-generated content like reviews, posts, or messages
When Not to Use
- Generic icons or logos - use an
imgelement or icon component instead - Status labels or categories - use Badge for metadata tags
- Decorative thumbnails or previews - use Aspect Ratio with a standard image
- Detailed user profile cards - use Hover Card for expanded user info on hover
Default
Avatar with image, rounded square variant, and stacked group.
Simple
Basic avatars with images and initials fallback.
Fallback
Avatar fallbacks with initials when no image is available. Use semantic color tokens for consistent theming.
Shapes
Different border radius options: circle (default), rounded-lg, rounded-md, and square.
Sizes
Available sizes using Tailwind size utilities: size-6, size-8 (default), size-10, size-12, size-16.
Group
Stacked avatar group with overlap effect using negative spacing and ring borders.
UX & Design Guidelines
Visual Hierarchy
Use larger avatars (size-12 or size-16) for profile headers and user detail views. Use the default size (size-8) in lists, comments, and navigation. Use small avatars (size-6) for compact contexts like inline mentions or dense tables.
Spacing & Layout
When placing avatars next to text, use gap-2 for tight layouts or gap-3 for standard spacing. For avatar groups, use -space-x-2 with ring-2 ring-background to create clean overlapping stacks. Limit groups to 3-5 visible avatars plus a count fallback.
Responsive Behavior
Avatar sizes should stay consistent across breakpoints to maintain recognizability. In responsive layouts, consider reducing group count on smaller screens rather than shrinking avatar size. The minimum recommended size is size-6 (24px) to keep initials legible.
Color & Contrast
Fallback backgrounds use bg-muted by default, ensuring sufficient contrast against text-foreground initials. For colored fallbacks, pair semantic tokens like bg-primary with text-primary-foreground to maintain WCAG 2.1 AA compliance. Group ring color should match the page background using ring-background.
Accessibility
Keyboard Navigation
- Tab — Move focus to interactive avatars (links or buttons wrapping avatars)
- Enter — Activate the wrapping interactive element (e.g., open profile)
- Non-interactive avatars are skipped in tab order, which is the expected behavior for decorative elements
Screen Reader Support
- Always provide meaningful
alttext on AvatarImage describing the person - When the user name is displayed adjacent to the avatar, use
alt=""to avoid redundant announcements - Fallback text (initials) is exposed to assistive technology - keep it meaningful
- Interactive avatars wrapped in buttons or links require
aria-labelon the wrapper
Focus Management
Avatars themselves are not focusable. When used inside interactive wrappers (buttons, links), the focus ring appears on the wrapper element. Ensure the wrapper has a visible focus indicator using focus-visible:ring-[3px] for WCAG 2.1 Level AA compliance.
Image Loading
The Avatar component gracefully degrades: if the image fails to load, AvatarFallback is displayed automatically. Use the delayMs prop on AvatarFallback to prevent flicker during fast connections. Screen readers announce the alt text regardless of whether the image has loaded.
ARIA Attributes
{/* Avatar with descriptive alt text */}
<Avatar>
<AvatarImage src="/photo.jpg" alt="Jane Doe, Product Manager" />
<AvatarFallback>JD</AvatarFallback>
</Avatar>
{/* Interactive avatar - requires aria-label */}
<button aria-label="View Jane Doe's profile">
<Avatar>
<AvatarImage src="/photo.jpg" alt="" />
<AvatarFallback>JD</AvatarFallback>
</Avatar>
</button>
{/* Avatar group with accessible label */}
<div
role="group"
aria-label="Team members"
className="flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background"
>
<Avatar>
<AvatarImage src="/user1.jpg" alt="Alice Smith" />
<AvatarFallback>AS</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage src="/user2.jpg" alt="Bob Jones" />
<AvatarFallback>BJ</AvatarFallback>
</Avatar>
</div>
{/* Decorative avatar (alt="" when name is adjacent) */}
<div className="flex items-center gap-2">
<Avatar>
<AvatarImage src="/photo.jpg" alt="" />
<AvatarFallback>JD</AvatarFallback>
</Avatar>
<span>Jane Doe</span>
</div>Related Components
Badge
Pair with avatars to show status indicators like online, busy, or away.
Card
Combine avatars with cards for user profile displays and team member lists.
Hover Card
Show expanded user details on hover, triggered by an avatar link.
Tooltip
Display the full user name on hover when only an avatar is visible.
API Reference
The Avatar component is composed of three parts. Each accepts standard HTML attributes in addition to the props below.
Avatar
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — | Additional CSS classes for the avatar container. Use size-* for custom sizes and rounded-* for shapes. |
| children | ReactNode | — | Should contain AvatarImage and AvatarFallback components. |
AvatarImage
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | — | The image source URL. |
| alt | string | — | Alternative text for the image. Required for accessibility. |
| className | string | — | Additional CSS classes for the image element. |
AvatarFallback
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Fallback content (usually initials) displayed when the image fails to load. |
| className | string | — | Additional CSS classes for the fallback container. |
| delayMs | number | — | Delay in milliseconds before showing the fallback after image load failure. |