Primary APIs:
TextBlock, SelectableTextBlock, Run, SpanFontSize, FontWeight, FontStyle, LineHeight, LetterSpacing)TextWrapping, TextTrimming, MaxLines)FormattedText)Reference docs:
59-media-colors-brushes-and-formatted-text-practical-usage.md58-textbox-editing-clipboard-undo-and-input-options.md| HTML/CSS | Avalonia |
|---|---|
font-family |
FontFamily |
font-size |
FontSize |
font-weight |
FontWeight |
font-style |
FontStyle |
line-height |
LineHeight |
letter-spacing |
LetterSpacing |
text-align |
TextAlignment |
HTML/CSS:
<h1 class="headline">Ship Faster UI</h1>
.headline {
font-family: "Inter", sans-serif;
font-size: clamp(2rem, 4vw, 3.25rem);
font-weight: 800;
letter-spacing: -0.02em;
line-height: 1.1;
}
Avalonia:
<TextBlock Classes="headline" Text="Ship Faster UI" />
<Style Selector="TextBlock.headline">
<Setter Property="FontFamily" Value="Inter" />
<Setter Property="FontSize" Value="48" />
<Setter Property="FontWeight" Value="ExtraBold" />
<Setter Property="LetterSpacing" Value="-0.6" />
<Setter Property="LineHeight" Value="52" />
</Style>
| HTML/CSS | Avalonia |
|---|---|
white-space: normal |
TextWrapping="Wrap" |
white-space: nowrap |
TextWrapping="NoWrap" |
word-break/overflow-wrap |
TextWrapping strategy + width constraints |
text-align: center/right |
TextAlignment |
HTML/CSS:
.summary {
max-width: 56ch;
white-space: normal;
}
Avalonia:
<TextBlock Classes="summary"
MaxWidth="640"
TextWrapping="Wrap"
Text="{CompiledBinding Summary}" />
HTML/CSS single-line ellipsis:
.title {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Avalonia:
<TextBlock Text="{CompiledBinding Title}"
TextWrapping="NoWrap"
TextTrimming="CharacterEllipsis" />
HTML/CSS multiline clamp:
.excerpt {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
Avalonia:
<TextBlock Text="{CompiledBinding Excerpt}"
TextWrapping="Wrap"
MaxLines="3"
TextTrimming="CharacterEllipsis" />
HTML:
<p>Deploy to <strong>production</strong> with <em>confidence</em>.</p>
Avalonia:
<TextBlock>
<Run Text="Deploy to " />
<Run Text="production" FontWeight="Bold" />
<Run Text=" with " />
<Run Text="confidence" FontStyle="Italic" />
<Run Text="." />
</TextBlock>
HTML/CSS:
<section class="hero-copy">
<h1>Design and ship native UI</h1>
<p>Use one codebase for desktop, mobile, and web targets.</p>
</section>
.hero-copy h1 { font-size: 3rem; margin-bottom: .5rem; }
.hero-copy p { font-size: 1.125rem; color: #9aa6bd; max-width: 52ch; }
Avalonia:
<StackPanel Classes="hero-copy" Spacing="8">
<TextBlock Classes="hero-title" Text="Design and ship native UI" />
<TextBlock Classes="hero-subtitle"
Text="Use one codebase for desktop, mobile, and web targets."
TextWrapping="Wrap"
MaxWidth="700" />
</StackPanel>
using Avalonia.Controls;
using Avalonia.Media;
var hero = new StackPanel { Spacing = 8 };
hero.Children.Add(new TextBlock
{
Text = "Design and ship native UI",
FontSize = 48,
FontWeight = FontWeight.ExtraBold,
LineHeight = 52
});
hero.Children.Add(new TextBlock
{
Text = "Use one codebase for desktop, mobile, and web targets.",
TextWrapping = TextWrapping.Wrap,
MaxWidth = 700,
Foreground = new SolidColorBrush(Color.Parse("#9AA6BD"))
});
FormattedText objects.HorizontalAlignment settings.