# Avatar
> User profile image with fallback initials and size control via the AvatarSize enum.
Source: https://shellui.dev/docs/v0.4/components/data-display/avatar
## Overview
The Avatar component displays a user profile image or fallback initials in a circular container. It uses the `AvatarSize` enum for sizing and `Shell.Cn()` for class merging.
## Installation
```bash
shellui add avatar
```
## Usage
### With Image
```razor
```
### With Fallback Initials
When no image is provided, or the image fails to load, the `Fallback` text is displayed:
```razor
```
### Image with Fallback
```razor
@code {
private UserInfo user = new("Ada Lovelace", "ada@example.com", "https://github.com/shadcn.png", IsActive: true);
record UserInfo(string Name, string Email, string AvatarUrl, bool IsActive);
private string GetInitials(string name)
{
var parts = name.Split(' ');
if (parts.Length >= 2)
return $"{parts[0][0]}{parts[1][0]}";
return name.Length > 0 ? name[0].ToString() : "";
}
}
```
### Sizes
The `Size` parameter accepts an `AvatarSize` enum value:
```razor
```
### User Profile Card
```razor
@code {
private UserInfo user = new("Ada Lovelace", "ada@example.com", "https://github.com/shadcn.png", IsActive: true);
record UserInfo(string Name, string Email, string AvatarUrl, bool IsActive);
private string GetInitials(string name)
{
var parts = name.Split(' ');
if (parts.Length >= 2)
return $"{parts[0][0]}{parts[1][0]}";
return name.Length > 0 ? name[0].ToString() : "";
}
}
```
### Custom Styling
```razor
```
## API Reference
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `Src` | `string?` | `null` | Image source URL |
| `Alt` | `string?` | `null` | Image alt text |
| `Fallback` | `string?` | `null` | Fallback text shown when no image loads |
| `Size` | `AvatarSize` | `AvatarSize.Default` | Avatar size |
| `Class` | `string?` | `null` | Additional CSS classes merged via `Shell.Cn()` |
### AvatarSize Enum
| Value | Description |
|-------|-------------|
| `Default` | Standard size (40 px) |
| `Sm` | Small (32 px) |
| `Lg` | Large (48 px) |
## Accessibility
- The `
` element receives the `Alt` text for screen readers.
- When only `Fallback` is shown, `aria-label` conveys the initials.
- Decorative avatars can set `Alt=""` to be hidden from assistive technology.