Avatar
View in Storybook
Explore interactive examples and all component variations in our Storybook.
The Avatar component displays user profile images with automatic fallback to initials or icons when images fail to load. Built on Radix UI Avatar primitive for maximum accessibility and reliability.
Basic Usage
CN
Different Sizes
CNCNCNCN
Fallback with Icon
User List
JS
John Smith
john@example.com
SJ
Sarah Johnson
sarah@example.com
MW
Mike Wilson
mike@example.com
ED
Emma Davis
emma@example.com
Avatar Group
JSM+2
Avatar with Status
JS
MS
PC
Properties
Avatar
| Property | Type | Description |
|---|---|---|
className | string | Additional CSS classes for the avatar container. |
AvatarImage
| Property | Type | Description |
|---|---|---|
src | string | URL of the avatar image. |
alt | string | Alternative text for the image. |
className | string | Additional CSS classes for the image. |
AvatarFallback
| Property | Type | Description |
|---|---|---|
children | ReactNode | Fallback content (initials, icon, etc.). |
className | string | Additional CSS classes for the fallback. |
Features
Automatic Fallback
- If the image fails to load, the fallback is displayed automatically
- Fallback can contain text (initials) or icons
- Smooth transition between image and fallback
Accessibility
- Full screen reader support
- Proper
altattributes for images - Correct semantic structure
- ARIA compliance through Radix UI
Recommended Sizes
| Context | Size | Classes |
|---|---|---|
| Compact list | 32px | h-8 w-8 |
| Standard list | 40px | h-10 w-10 (default) |
| Profile | 64px | h-16 w-16 |
| Header/Hero | 80px+ | h-20 w-20 |
Common Use Cases
The Avatar component is perfect for:
- User profiles - Display user profile pictures in applications
- Comment systems - Show commenter avatars in discussions
- Team members - Display team member photos in about pages
- Contact lists - Show contact photos in messaging apps
- Author bylines - Display author photos in blog posts
- User directories - Show user avatars in member listings
- Navigation bars - Display current user avatar in headers
Best Practices
- Always provide fallback - Use initials or icons when images aren't available
- Use appropriate alt text - Describe the user or context of the image
- Maintain aspect ratio - Always use square dimensions (same height and width)
- Optimize images - Use optimized images of appropriate size
- Consider loading states - Implement skeleton or placeholder during loading
- Test fallbacks - Verify how the component behaves without images
- Accessibility first - Ensure it works well with screen readers