Avatar
Avatar components are used to represent a user and can display images, initials, or fallback icons.
Installation
Add the avatar component to your project:
Usage
Default Avatar
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Sizes
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
With Status
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Shapes
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Fallback
Avatar
Live preview rendered from the registry in an isolated iframe.
Loading preview...
Failed to load preview
Avatar
Full preview from the registry iframe.
Loading preview...
Props
| Prop | Type | Default | Description |
|---|---|---|---|
src |
string |
null |
Image URL for the avatar |
name |
string |
null |
User's name (used for initials and alt text) |
size |
string |
'xl' |
Size of the avatar: xs, sm, md, lg, xl |
shape |
string |
'circle' |
Shape of the avatar: circle or square |
status |
string |
null |
Status indicator: online, offline, busy, away |
fallbackIcon |
string |
'user' |
Icon name to show when no image is provided |
Examples
Avatar Group
<div class="flex -space-x-2">
<x-ui.avatar
src="https://i.pravatar.cc/128?img=1"
name="Alice"
size="sm"
/>
<x-ui.avatar
src="https://i.pravatar.cc/128?img=2"
name="Bob"
size="sm"
/>
<x-ui.avatar
src="https://i.pravatar.cc/128?img=3"
name="Charlie"
size="sm"
/>
<x-ui.avatar
name="+5"
size="sm"
fallback-icon="plus"
/>
</div>
User Profile Card
<div class="flex items-center gap-4 p-4 border rounded-lg">
<x-ui.avatar
src="https://i.pravatar.cc/128?img=12"
name="Jane Cooper"
size="lg"
status="online"
/>
<div>
<p class="font-medium">Jane Cooper</p>
<p class="text-sm text-muted-foreground">Product Designer</p>
</div>
</div>
With Initials
<x-ui.avatar
name="Jane Cooper"
fallback-icon="user"
size="xl"
/>
Accessibility
Avatar components include proper ARIA attributes:
- Alt text generated from the
nameprop - Proper semantic HTML structure
- Status indicators with ARIA labels
Customization
The avatar component uses Tailwind CSS classes. You can customize the appearance by modifying the component in your project:
@
@props([
'src' => null,
'name' => null,
'size' => 'xl',
'shape' => 'circle',
'status' => null,
'fallbackIcon' => 'user',
])
// Customize sizes, colors, and styles here
Size Customization
The avatar supports the following sizes:
xs: 24pxsm: 32pxmd: 40pxlg: 48pxxl: 56px
Status Colors
online: Greenoffline: Graybusy: Redaway: Yellow
Next Steps
- Explore Avatar Group component
- Learn about Badge component
- View Card component