Avatar
An image of a person, falling back to initials when there is none or it fails to load.
On this page
Examples
Images and fallbacks
Razor
<div class="flex flex-wrap items-center gap-3">
@foreach (var size in Enum.GetValues<KlySize>())
{
<KlyAvatar Size="size" Alt="Grace Hopper" />
}
<KlyAvatar Size="KlySize.Lg" Src="https://i.pravatar.cc/80?img=47" Alt="Profile photo" />
@* A broken image falls back to the initials. *@
<KlyAvatar Size="KlySize.Lg" Src="/missing.png" Alt="Ada Lovelace" />
</div>API
KlyAvatar
Round picture of a person or entity, with an icon or initials fallback when the image is missing or fails to load.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Alt |
string |
Text alternative; its initials are shown when there is no image or it fails to load. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor? |
A color that tints the avatar and its initials. Without it the avatar is neutral. Values: primary, secondary, success, info, warning, error, neutral. |
|
ImageOptions |
KlyImageOptions |
Image settings forwarded to KlyImage : new KlyImageOptions { Format = KlyImageFormat.WebP, Quality = 80 } . The avatar passes its size in pixels as the width and the height, so a provider can serve a picture of that size. | |
Size |
KlySize |
KlySize. |
Size of the avatar, from Xs to Xl ; it also sets the pixel size asked of the image provider. Values: Xs, Sm, Md, Lg, Xl. |
Src |
string |
Address of the picture. When it is missing or fails to load, the avatar shows its text or icon. | |
Text |
string |
Fallback text instead of the initials of Alt . | |
Ui |
AvatarUi |
Per-instance class overrides of the slots of the avatar, see AvatarUi . They are merged after the theme and the Class parameter wins on the root slot. |
Slots
| Name | Type | Description |
|---|---|---|
Icon |
RenderFragment |
Icon shown when there is no picture and no text, as markup such as a KlyIcon . |
Ui slots
Ui takes a AvatarUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyAvatar and KlyColorModeAvatar , after the theme and the app configuration. |
Image |
Classes merged into the image slot of KlyAvatar and KlyColorModeAvatar , after the theme and the app configuration. |
Fallback |
Classes merged into the fallback slot of KlyAvatar and KlyColorModeAvatar , after the theme and the app configuration. |