Align a line or a paragraph

    Apply paragraph alignment at the current selection through the Formatting service. Alignment belongs to the document block rather than the native toolbar layout.

    Use the selection and state APIs when your application provides its own formatting controls.

    A selected project heading centered in Avalonia HTML Editor, with its bold and alignment state reflected in the toolbar.
    A selected project heading centered in Avalonia HTML Editor, with its bold and alignment state reflected in the toolbar.

    Use it in your application

    Place the caret in the intended paragraph, or select the paragraphs to format, before applying alignment.

    Await each operation. Paragraph alignment requires editable Design mode. Source mode supports its own limited inline tag operations; switch to Design before aligning paragraphs.

    Use StateQuery to update an application-owned alignment indicator from the actual current view.

    await editor.Formatting.AlignCenterAsync();
    bool centered = await editor.StateQuery.IsJustifyCenterAsync();
    

    Continue with

    Last updated on Oct 30, 2026

    Put this into practice.

    Start with the C# Avalonia sample. Restore this edition's package and install the native browser prerequisites before running it.

    Prefer a guided look? Book a free live demo with our engineers - live on Zoom or Teams, never a chatbot.