Avatar

in namespace DotVVM.Controls.Tailwind.Controls

Displays a user avatar with image or initials.

Usage & Scenarios

Displays a user avatar using an image or initials. Use Size to switch between the built-in avatar sizes.

Sample 1: Avatar with Initials and Image

Shows avatars using initials and image URLs in Small, Default, and Large sizes.

<div class="flex flex-col gap-6">
    <div class="flex items-center gap-4">
        <h3 class="text-sm font-semibold">Avatar Types:</h3>
        <t:Avatar ImageUrl="https://i.pravatar.cc/150?img=3" AltText="User photo" />
        <t:Avatar Initials="JS" />
        <t:Avatar />
    </div>
    
    <div class="flex items-center gap-4">
        <h3 class="text-sm font-semibold">Avatar Sizes:</h3>
        <t:Avatar Initials="AB" Size="Small" />
        <t:Avatar Initials="CD" Size="Default" />
        <t:Avatar Initials="EF" Size="Large" />
        <t:Avatar Initials="XL" Size="ExtraLarge" />
    </div>
</div>

Dynamic avatar image and bindable initials

This sample demonstrates how to bind the avatar image URL and alt text, change the avatar size via a ComboBox and bind initials from a TextBox.

<div class="flex flex-col gap-6">
    <div class="flex items-center gap-4">
        <div>
            <label class="text-sm font-semibold">Initials:</label>
            <t:TextBox Text="{value: InitialsText}" class="mt-1 p-2 border border-gray-300 rounded-md" />
        </div>
        <t:Avatar Initials="{value: InitialsText}" />
    </div>
    
    <div class="flex items-center gap-4">
        <div>
            <label class="text-sm font-semibold">Size:</label>
            <t:ComboBox DataSource="{value: AllSizes}" SelectedValue="{value: SelectedSize}" class="mt-1" />
        </div>
        <t:Avatar Initials="JS" Size="{value: SelectedSize}" />
    </div>
</div>

using System;
using DotVVM.Framework.ViewModel;

public class ViewModel : DotvvmViewModelBase
{
    public string DynamicImageUrl { get; set; } = "https://i.pravatar.cc/150?img=2";
    public string DynamicAltText { get; set; } = "User avatar";
    public ControlSize SelectedSize { get; set; } = ControlSize.Default;
    public ControlSize[] AllSizes { get; set; } = (ControlSize[])Enum.GetValues(typeof(ControlSize));
    public string InitialsText { get; set; } = "AB";
}

Properties

Name Type Description Notes Default Value
property icon AltText String Gets or sets the alternative text for the avatar image.
attribute
inner element
static value
bindable
default
null
property icon ImageUrl String Gets or sets the URL of the avatar image.
attribute
inner element
static value
bindable
default
null
property icon Initials String Gets or sets the fallback initials displayed when no image is provided.
attribute
inner element
static value
bindable
default
null
property icon Size ControlSize Gets or sets the visual size of the avatar.
attribute
inner element
static value
bindable
default
Default
property icon Visible Boolean Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control.
attribute
inner element
static value
bindable
default
True

HTML produced by the control