---
title: "Show avatar fallback initials in C#"
url: https://recursiveai.org/oneapp/cookbook/show-initials-when-avatar-image-is-unavailable/
description: "Show initials when a profile photo is missing in a C# desktop UI. Set OneApp Kit’s Avatar fallback and alternate text, then run the example."
version: "1.1.1"
---

This example opens a native window. For phone and tablet builds, see [OneApp’s mobile setup](https://recursiveai.org/oneapp/docs/mobile/).

```shell
dotnet add package RecursiveAI.OneApp.Kit
dotnet add package RecursiveAI.OneApp
dotnet add package RecursiveAI.OneUI
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```html
<Avatar Src="missing-photo.png"
        Alt="Portrait of Maya Chen"
        Fallback="MC" />
```

[The example](https://recursiveai.org/oneapp/cookbook/show-initials-when-avatar-image-is-unavailable/show-initials-when-avatar-image-is-unavailable.zip) is the full program below: unzip it and `dotnet run`.

This goes in `ProfilePage.html`. The sample deliberately leaves `missing-photo.png` unregistered. No image file or network connection is needed by the running app.

## The full program

`OneApp` opens the window; `OneApp.Kit` supplies `Avatar`; `OneUI` compiles your markup.

Put `ProfilePage.html` next to `ProfilePage.cs` in the project folder. The OneUI markup compiler [matches the template to the partial class by name](https://github.com/recursive-ai-oss/oneapp-csharp/blob/b93a90dc510817e92a4ebd1e340b83118461665c/README.md#L23-L27), so no extra build item is needed.

`ProfileDemo.csproj`:

```xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference
      Include="RecursiveAI.OneApp"
      Version="1.1.1" />
    <PackageReference
      Include="RecursiveAI.OneApp.Kit"
      Version="1.1.1" />
    <PackageReference
      Include="RecursiveAI.OneUI"
      Version="1.1.0" />
  </ItemGroup>
</Project>
```

`ProfilePage.html`:

```html
<Theme>
  <main style="padding: 24px">
    <Avatar Src="missing-photo.png"
            Alt="Portrait of Maya Chen"
            Fallback="MC" />
    <p>Maya Chen</p>
  </main>
</Theme>
```

`ProfilePage.cs`:

```csharp
public partial class ProfilePage
{
}
```

`Program.cs` opens the window with the `ProfilePage` component defined above:

```csharp
using OneApp;

var options = new AppOptions(new ProfilePage())
{
    Title = "Profile",
    Width = 340,
    Height = 190,
};
using var host = AppHost.Create(options);
host.Run();
```

The window shows **MC** above **Maya Chen**, with no terminal output (checked on Linux (X11)).

![The Profile window showing MC inside a circle above the name Maya Chen](https://recursiveai.org/oneapp/images/show-initials-when-avatar-image-is-unavailable/initials.png)

If you get a blank circle instead of initials when the picture is missing, check `Fallback`: `Avatar` doesn’t turn `Alt` or a display name into initials for you.

## Variations

If you already know there’s no photo, omit `Src`. Use the small size for a compact contact list:

```html
<Avatar Fallback="MC"
        Size="{OneApp.Kit.ControlSize.Sm}" />
```

## Related recipes

- [Build a C# desktop app with HTML and CSS](https://recursiveai.org/oneapp/cookbook/build-desktop-app-with-html-css/)
- [Customize the desktop UI kit theme](https://recursiveai.org/oneapp/cookbook/theme-desktop-ui-kit/)

## The short answer

Set `Fallback` to the initials you want to display, `Src` to the photo’s address, and `Alt` to the photo’s text alternative. Leave `Src` out when there’s no photo. Keep the full name in the surrounding UI so users don’t have to guess who the initials represent.

## How do I display initials when an avatar image fails to load?

Set `Fallback` even when you have a photo address. The kit renders the initials behind the image, so there’s already something to show if the image doesn’t draw. You don’t need a second component or an app-side error handler just to get initials. An omitted or empty `Src` makes the kit skip the image altogether.

In a native OneApp window, an image address isn’t a request to read that file from disk or fetch it from the web. The host resolves registered image addresses and supports `data:` images; see [OneApp’s page image notes](https://recursiveai.org/oneapp/docs/shell/#windows-1). An unregistered address is how this example demonstrates the fallback without shipping or downloading a photo. In an app that has contact data, use the initials supplied by the user or kept with the profile instead of assuming every name has two words.

## What alt text should I use for an avatar?

`Fallback` is visible text; `Alt` is the text alternative for the image element. If a photo itself conveys meaningful information, describe that information briefly. If it just repeats the identity given by an adjacent name, `Alt=""` is appropriate so the name needn’t be read twice. The [W3C’s alt text decision tree](https://www.w3.org/WAI/tutorials/images/decision-tree/) makes that distinction. `Alt` doesn’t label the entire avatar: when no image element is rendered, there’s no image alternative to read. Keep the full name independently readable in either case.
