Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 42 ยท Styling and Resources

Fonts, Images and Icons

Add custom fonts, SVG and PNG images, the app icon and splash screen to a .NET MAUI app, understand density-independent sizing and font scaling, and pick the right asset format.

Branding lives in your fonts, images and icons. MAUI treats them as resources in the project: you drop files into folders, and the build converts them into whatever each platform needs. You never create drawable-hdpi, @2x or .appiconset folders by hand. This lesson shows where files go, how to use them in XAML, and how sizes and scaling work.

MAUI itself cannot run on this site, so project files and XAML are read-only. The runnable examples are C# stand-ins for the calculations the build tools and the UI make for you.

Fonts

Put .ttf or .otf files in Resources/Fonts. They are included automatically (the project file has <MauiFont Include="Resources\Fonts\*" />). Register each font and give it an alias in MauiProgram.cs:

C#
builder
    .UseMauiApp<App>()
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("Inter-Regular.ttf", "InterRegular");
        fonts.AddFont("Inter-SemiBold.ttf", "InterSemiBold");
    });

Use the alias anywhere a FontFamily is accepted:

XML
<Label Text="Welcome" FontFamily="InterSemiBold" FontSize="28" />

Best practice is to set the family once in an implicit style, so every label uses it:

XML
<Style TargetType="Label">
    <Setter Property="FontFamily" Value="InterRegular" />
</Style>

Each weight is a separate file and a separate alias, because the font family name alone does not pick bold. FontAttributes="Bold" may fake a bold when no bold file exists, which usually looks worse than a real one.

Font scaling

FontAutoScalingEnabled (default true) makes text follow the user's system font size setting. That is an accessibility feature: leave it on, and design layouts that survive a 200% text size (use Grid rows with Auto height rather than fixed heights).

Icon fonts

A font can contain symbols instead of letters (Material Symbols, Font Awesome). Register it as above and display glyphs by their Unicode code point:

XML
<Label FontFamily="MaterialSymbols" Text="&#xE88A;" FontSize="24" />

Icon fonts scale perfectly, take one file and can be recolored with TextColor. A FontImageSource turns a glyph into an image for places that need an ImageSource, such as a toolbar item.

Images

Put images in Resources/Images. The project file includes <MauiImage Include="Resources\Images\*" />, and the build produces the correct sizes for each platform.

XML
<Image Source="dotnet_bot.png" Aspect="AspectFit" HeightRequest="200"
       SemanticProperties.Description="Cute robot waving" />

Rules for file names are strict, because they become identifiers on Android:

  • lowercase letters, digits and underscores only, starting with a letter,
  • no spaces, dashes or capitals (dotnet_bot.png, not Dotnet-Bot.png),
  • reference them without a folder name.

SVG is the default choice

Vector files (.svg) are converted to PNGs at each density during the build, so one file serves every screen and stays sharp. Use BaseSize to say what the natural size is:

XML
<MauiImage Update="Resources\Images\logo.svg" BaseSize="128,128" />

If you do not set BaseSize, the SVG's own width and height are used. Raster files (PNG, JPG) are only scaled down, never up, so supply the largest size you need and name it without density suffixes.

You can tint a vector or bitmap at build time with TintColor:

XML
<MauiImage Update="Resources\Images\icon_home.svg" TintColor="#512BD4" />

or at runtime with the IconTintColorBehavior from the Community Toolkit.

Image sources

An ImageSource can be loaded from different places:

Kind Example Notes
Resource file Source="logo.png" Built into the app, fastest
URL Source="https://example.com/a.jpg" Downloaded and cached
Stream ImageSource.FromStream(() => stream) Camera data, database blobs
Font glyph FontImageSource Icon fonts

For web images, set a placeholder, because the download takes time.

Density-independent units

MAUI measures in device-independent units, not pixels. One unit is about 1/160 inch on Android and a point on iOS. A HeightRequest="48" is the same physical size on a cheap phone and on a tablet. The device density tells you how many pixels that is, and an SVG renders at that density. This calculator shows what the build does for a 64x64 base image on Android density buckets:

C# Stand-in: image sizes per Android density

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

App icon and splash screen

The app icon is configured in the project file:

XML
<MauiIcon Include="Resources\AppIcon\appicon.svg"
          ForegroundFile="Resources\AppIcon\appiconfg.svg"
          Color="#512BD4" />

<MauiSplashScreen Include="Resources\Splash\splash.svg"
                  Color="#512BD4" BaseSize="128,128" />
  • Include is the background layer and ForegroundFile the foreground. Android adaptive icons use both layers, with a safe zone in the middle (about the inner two thirds), so keep important artwork centered.
  • Color fills the background and the splash screen.
  • The splash screen is shown while the app starts; it is not a place to keep the user waiting. Show the first real page quickly (see App Lifecycle).

The build generates every icon size each store requires, so you only need one square vector file (or a 1024x1024 PNG).

Image performance

Large photos cost memory (a 12 MP picture decodes to roughly 46 MB). Some habits:

  • Display thumbnails in lists and load the full image only on a detail page.
  • Resize on the server, or resize once when saving a picture from the camera.
  • Set IsOpaque="True" on images with no transparency.
  • Avoid animating many large images at once.

The memory a decoded bitmap uses depends on its pixel size, not its file size. A quick check:

C# Stand-in: decoded bitmap memory

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

A list showing twenty 12 MP photos at once would need around a gigabyte, which is why the app would be killed. Down-sampling is not optional for photo apps.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In which folder do custom font files go in a standard MAUI project?

    Files in Resources/Fonts are picked up by MauiFont and then registered with ConfigureFonts and an alias.
  2. 2. Which file name is valid for a MAUI image?

    Names must be lowercase letters, digits and underscores because they become Android resource identifiers.
  3. 3. Why is SVG the recommended format for logos and icons?

    A vector file is rasterized for each screen density at build time, so one file serves every device.
  4. 4. What does a 12-megapixel photo cost in memory once decoded (RGBA)?

    12 million pixels times 4 bytes is about 46 MB, no matter how small the compressed file is.

Summary

  • Fonts go in Resources/Fonts and are registered with ConfigureFonts and an alias; one file per weight.
  • Images go in Resources/Images, with lowercase underscore names; prefer SVG and set BaseSize.
  • Units are device independent; the build creates every pixel size for you.
  • MauiIcon and MauiSplashScreen generate the app icon and splash screen from vector files.
  • Decoded images cost width x height x 4 bytes, so down-sample for lists.

Next: Animations and Custom Handlers