Rich text editing with HTML output

    Rich text editors for Avalonia fall into two groups: editors built around a document model, saved as RTF, DOCX or XAML, and HTML editors, which save HTML. The right choice depends on where the formatted content is used after the user saves it. This guide gives the deciding factors and the code to load and save content with the Avalonia HTML Editor.

    The real SpiceLogic Avalonia HTML Editor with a formatted sample HTML template, its complete editing toolbars, and Design, Source and Preview controls.
    The real SpiceLogic Avalonia HTML Editor with a formatted sample HTML template, its complete editing toolbars, and Design, Source and Preview controls.
    Choose by the saved format: RTF, DOCX or XAML for document-format workflows; HTML for email bodies, reusable templates and web content.
    Choose by the saved format: RTF, DOCX or XAML for document-format workflows; HTML for email bodies, reusable templates and web content.

    Decide by where the content goes

    Formatting on screen looks the same in both kinds of editor. The difference is the format you are left holding afterwards.

    What you needDocument-format editorAvalonia HTML Editor
    Saved formatRTF, DOCX or XAMLHTML
    Send the content as an email bodyConvert to HTML firstUse the saved HTML as it is
    Show the content on a web page or in a reportConvert to HTML firstUse the saved HTML as it is
    Open and save word-processing filesThe natural fitPaste from Word with cleanup
    Source view for the markupNot applicableIncluded, with a preview

    When a document-format editor fits

    Choose a document-format editor when the application works with word-processing files: users open, edit and save RTF or DOCX documents, and the content stays in that format.

    When to choose an HTML editor

    Choose the HTML Editor when the content is destined for email or the web. Typical cases:

    • Users compose email messages or reusable email templates that your application sends.
    • Content is stored in a database and later shown on a website, a customer portal or a report.
    • Users paste from Word or Outlook and expect the formatting to arrive intact.
    • The same application runs on Windows, macOS and Linux and must produce identical HTML on each.

    In each case the editor already produces the format the destination expects, so there is no conversion layer to write, test and maintain.

    Load and save HTML

    Add the control from NuGet (dotnet add package SpiceLogic.HtmlEditor.Avalonia), place it in a window, then read and write the content through the Content service once the editor is ready:

    await editor.Ready;
    
    // Load the saved message into the editor
    await editor.Content.SetBodyHtmlAsync(template.Body);
    
    // Save what the user wrote
    template.Body = await editor.Content.GetBodyHtmlAsync();
    

    The saved string is ready to use as an email body or to store in a text column. Use GetDocumentHtmlAsync when you need the complete document, including the head.

    Next steps

    Last updated on Nov 11, 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.