Get and set HTML

    Choose the content boundary that matches your storage. Body HTML is a fragment for application content; document HTML includes the head, metadata and styles.

    Saved HTML message reopened in the Avalonia editor with its added sentence, headings, table and list retained.
    Saved HTML message reopened in the Avalonia editor with its added sentence, headings, table and list retained.
    await editor.Ready;
    await editor.Content.SetBodyHtmlAsync("<p>Hello</p>");
    string fragment = await editor.Content.GetBodyHtmlAsync();
    string fullDocument = await editor.Content.GetDocumentHtmlAsync();

    Use SetDocumentHtmlAsync when replacing a complete document. Setting body HTML preserves the accepted document head. Content export applies pending source changes; if newer edits remain or an operation fails, keep the source draft visible and handle the error before saving.

    Bound properties and awaited results

    BodyHtml and DocumentHtml are bindable properties reflecting accepted editor content. Use an awaited setter or getter when the next application operation depends on completion. The native Border.Child property owns the visual tree; Content is the replaceable awaited authoring facade.

    Save accepted content

    A body replacement retains supported head metadata and styles. A full document replacement establishes a new document identity. Private raster display transport is removed from exported HTML; explicitly embedded image data belongs to the authored document and remains in exports.

    XHTML and XML export

    The XHTML overloads convert through the shared normalizer to well-formed XML-compatible output. The XML method adds a UTF-8 declaration. They apply a pending Source draft first and retain the current URL, doctype and generator policy. Invalid XML characters, unbound namespace prefixes, internal DTD subsets and excessive size or depth report an error; they never replace the accepted document.

    string xhtmlFragment = await editor.Content.GetBodyHtmlAsync(true);
    string xhtmlDocument = await editor.Content.GetDocumentHtmlAsync(true);
    string xmlDocument = await editor.Content.GetDocumentXmlAsync();

    Last updated on Oct 18, 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.