Insert HTML at the caret

    Insert prepared markup or literal text through the Content service. The current view determines whether an operation changes the rendered document or the visible Source draft.

    Use text insertion for values that must remain literal, and HTML insertion for markup your application intentionally supplies.

    Actual Avalonia authoring surface with a document ready for caret-based insertion.
    Actual Avalonia authoring surface with a document ready for caret-based insertion.

    Use it in your application

    Wait for readiness, place or restore the caret, then await the insertion. Read-only mode rejects authoring operations.

    A Source draft has its own undo history. A fresh export applies that draft or reports why it cannot apply, rather than exporting an older hidden document.

    For reusable application-defined fields, use the mail-merge service instead of concatenating untrusted values into markup.

    await editor.Caret.SetCaretAtEndAsync();
    await editor.Content.InsertHtmlAsync("<p><strong>Delivery note</strong></p>");
    await editor.Content.InsertTextAsync("Reference: A&B <confirmed>");

    Continue with

    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.