Skip to main content

Text options

Avalonia provides fine-grained control over how text is rendered through the TextOptions attached properties. These settings affect hinting, pixel alignment, and rendering mode for text within a control and its descendants.

Properties

Attached propertyTypeDefaultDescription
TextOptions.TextRenderingModeTextRenderingModeAutoControls whether text uses anti-aliasing, ClearType/subpixel rendering, or aliased rendering.
TextOptions.TextHintingModeTextHintingModeFullControls how font hinting is applied. Hinting adjusts glyph outlines to align with the pixel grid for sharper text at small sizes.
TextOptions.BaselinePixelAlignmentBaselinePixelAlignmentUnspecifiedControls whether text baselines snap to whole pixel boundaries.

TextRenderingMode

ValueDescription
AutoThe platform chooses the best rendering mode.
AliasText is rendered without anti-aliasing. Produces sharp but jagged edges, useful for pixel-art fonts or very small text.
AntialiasText is rendered with grayscale anti-aliasing.
SubpixelAntialiasText is rendered with subpixel anti-aliasing (e.g., ClearType on Windows). Produces the sharpest text on LCD displays.
<TextBlock Text="Aliased text"
TextOptions.TextRenderingMode="Alias" />

<TextBlock Text="Subpixel text"
TextOptions.TextRenderingMode="SubpixelAntialias" />

TextHintingMode

Font hinting adjusts glyph outlines so they align with the pixel grid. This improves readability at small sizes but can distort glyph shapes. Reducing or disabling hinting preserves the original typeface design, which is preferable for large text or animated text.

ValueDescription
NoneNo hinting. Glyphs use their original outlines. Best for large or animated text.
SlightMinimal hinting. Adjusts vertical metrics only, preserving horizontal glyph shapes.
NormalModerate hinting.
FullFull hinting (default). Maximum pixel-grid alignment for sharpest small text.
<!-- Large heading with no hinting for smooth outlines -->
<TextBlock Text="Welcome"
FontSize="48"
TextOptions.TextHintingMode="None" />

<!-- Body text with full hinting for maximum readability -->
<TextBlock Text="Read the details below."
FontSize="14"
TextOptions.TextHintingMode="Full" />

BaselinePixelAlignment

Controls whether text baselines snap to whole pixel boundaries. Pixel-aligned baselines produce sharper text in static layouts. Unaligned baselines allow sub-pixel positioning, which prevents text from "jumping" during animations or smooth scrolling.

ValueDescription
UnspecifiedThe platform decides (typically aligned for static text).
AlignedBaselines snap to the nearest pixel. Best for static UI text.
UnalignedBaselines use sub-pixel positioning. Best for animated or smoothly scrolled text.
<!-- Prevent text snapping during a RenderTransform animation -->
<TextBlock Text="Sliding text"
TextOptions.BaselinePixelAlignment="Unaligned">
<TextBlock.RenderTransform>
<TranslateTransform />
</TextBlock.RenderTransform>
</TextBlock>

Applying to a container

Like RenderOptions, TextOptions is inherited by child controls. Set it on a container to affect all text within:

<StackPanel TextOptions.TextHintingMode="None"
TextOptions.BaselinePixelAlignment="Unaligned">
<TextBlock Text="All text in this panel" />
<TextBlock Text="uses no hinting and sub-pixel baselines." />
</StackPanel>

Setting from code

TextOptions.SetTextHintingMode(myControl, TextHintingMode.None);
TextOptions.SetBaselinePixelAlignment(myControl, BaselinePixelAlignment.Unaligned);

See also