Skip to main content
twblazor
Home
  • Get started
  • Tailwind with Blazor
  • Why twblazor?
  • Theme
  • Class Merge
    • Configuring localization
    • RTL Provider
  • Breadcrumb
  • Card
  • Carousel
  • Collapse
  • Context Menu
  • Drawer
  • Footer
  • Menu
  • Navbar
  • On This Page
  • Separator
  • Sidebar
  • Stepper
  • Tabs
  • Tree List
  • Container
  • Flex
  • Grid
  • Text
  • Link
  • Button
  • Form
    • AutocompleteNew
    • Checkbox
    • Color Picker
    • Date Picker
    • Date Range Picker
    • Datetime Picker
    • Datetime Range Picker
    • File Upload
    • Input GroupNew
    • NumericNew
    • Masked InputNew
    • Radio Button
    • Range SliderNew
    • RatingNew
    • Select
    • Slider
    • Switch
    • Tag InputNew
    • Text EditorNew
    • Textfield
    • Time Picker
    • Time Range Picker
  • Toggle
  • Toggle Group
  • Alert
  • Avatar
  • Badge
  • Chip
  • Empty
  • Icon
  • Popover
  • Progress
  • Skeleton
  • Spinner
  • Tooltip
  • Data Table
  • SpreadsheetNew
  • Column Filter Editor
  • Pagination
  • Pick List
  • Barcode
  • QR Code
  • Calendar
  • Table
  • Attachment
  • Overview
    • Bar
    • Bullet
    • Column
    • Dot Plot
    • Dumbbell
    • Icon
    • Lollipop
    • Radial Bar
    • Range
    • Word Cloud
    • Area
    • Bump
    • Bump Area
    • Candlestick
    • Gantt
    • Horizon
    • Line
    • Slope
    • Small Multiples
    • Stream Graph
    • Funnel
    • Gauge
    • Marimekko
    • Nightingale
    • Pie
    • Treemap
    • Waffle
    • Waterfall
    • Circular Treemap
    • Convex Treemap
    • Dendrogram
    • Sunburst
    • Barcode
    • Beeswarm
    • Box Plot
    • Density Plot
    • Histogram
    • Radial Histogram
    • Ridgeline
    • Strip Plot
    • Violin Plot
    • Categorical Scatter
    • Contour
    • Hexagonal Binning
    • Quadrant
    • Scatter
    • Heatmap
    • Matrix
    • Parallel Coordinates
    • Radar
    • Arc Diagram
    • Chord Diagram
    • Flowchart
    • Network Diagram
    • Sankey
    • Euler Diagram
    • Venn Diagram
  • Bubble
  • Marker
  • Message
  • Dialog Service
  • Toast Service
API DocumentationAI Agents & Skills
Home Get Started

Forms

TwTextEditor

TwTextEditor is a Blazor rich text editor that binds HTML. Add headings, bold text, lists, quotes and links from a toolbar or with keyboard shortcuts.

Last updated 8 November 2026

Please be aware this component is new, may have bugs and/or be subject to change. Please report any bugs at https://github.com/twblazor/twblazor/issues.

Basic usage

Bind the content with @bind-Value to a string of HTML. The default Standard toolbar has a text style list, bold, italic, underline, strikethrough, lists and links. The value only ever holds the tags the editor produces, and an empty editor binds as an empty string.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U) Strikethrough (Ctrl+Shift+X)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Link (Ctrl+K)
Press Alt+F10 to move to the toolbar.

Value:

<h2>Release notes</h2><p>This release adds a <strong>rich text editor</strong> with <em>headings</em>, lists and links.</p><ul><li>Bind the content as HTML</li><li>Use keyboard shortcuts</li></ul>
RAZOR
<TwTextEditor Label="Description" Placeholder="Write something..." @bind-Value="basicHtml" />
<p class="mt-3 text-sm text-gray-600 dark:text-gray-400">Value:</p>
<pre class="mt-1 rounded-md bg-black/5 p-3 text-xs whitespace-pre-wrap wrap-anywhere dark:bg-white/10">@basicHtml</pre>
CSHARP
@code {
    private string? basicHtml = "<h2>Release notes</h2><p>This release adds a <strong>rich text editor</strong> with <em>headings</em>, lists and links.</p><ul><li>Bind the content as HTML</li><li>Use keyboard shortcuts</li></ul>";
}

Toolbar presets

Toolbar chooses the controls, and each preset holds every control of the one before it. Simple has bold, italic, underline and lists. Standard adds the text style list, strikethrough and links. Full adds quotes, code blocks, clear formatting, undo, redo and an HTML source view.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U) Strikethrough (Ctrl+Shift+X)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Quote (Ctrl+Shift+9) Code block
Link (Ctrl+K)
Clear formatting (Ctrl+\) Undo (Ctrl+Z) Redo (Ctrl+Y)
HTML source
Press Alt+F10 to move to the toolbar.
RAZOR
<div class="flex flex-col gap-6">
    <TwTextEditor Label="Simple" Toolbar="TextEditorToolbar.Simple" MinHeight="80px" Value="@presetHtml" />
    <TwTextEditor Label="Full" Toolbar="TextEditorToolbar.Full" MinHeight="80px" Value="@presetHtml" />
</div>

No toolbar

With TextEditorToolbar.None there is no toolbar, but the keyboard shortcuts still work: Ctrl + B, Ctrl + I and Ctrl + U for bold, italic and underline, and Ctrl + Shift + 8 for a bulleted list. Use it for inline editing, or with your own controls calling the editor's methods.
RAZOR
<TwTextEditor Label="Note" Toolbar="TextEditorToolbar.None" MinHeight="80px" Placeholder="Try Ctrl + B" @bind-Value="noteHtml" />
CSHARP
@code {
    private string? noteHtml;
}

Custom toolbar

ToolbarContent adds controls to the end of the toolbar, or makes up the whole toolbar with TextEditorToolbar.Custom. Its context is the editor, so a control can call FormatAsync and show its state with IsActive. Here each control is a TwToggle.
Press Alt+F10 to move to the toolbar.
RAZOR
<TwTextEditor Label="Headline" Toolbar="TextEditorToolbar.Custom" MinHeight="80px">
    <ToolbarContent>
        <TwToggle Icon="Icon.Type_H1" Size="Size.Sm" AriaLabel="Heading" Pressed="@context.IsActive(TextEditorFormat.Heading1)" PressedChanged="@(_ => context.FormatAsync(context.IsActive(TextEditorFormat.Heading1) ? TextEditorFormat.Paragraph : TextEditorFormat.Heading1))" />
        <TwToggle Icon="Icon.Type_Bold" Size="Size.Sm" AriaLabel="Bold" Pressed="@context.IsActive(TextEditorFormat.Bold)" PressedChanged="@(_ => context.FormatAsync(TextEditorFormat.Bold))" />
        <TwToggle Icon="Icon.Quote" Size="Size.Sm" AriaLabel="Quote" Pressed="@context.IsActive(TextEditorFormat.Blockquote)" PressedChanged="@(_ => context.FormatAsync(TextEditorFormat.Blockquote))" />
    </ToolbarContent>
</TwTextEditor>

Height

MinHeight (150px by default) sets where the editing area starts. With MaxHeight it grows with its text up to that height and then scrolls, and Height fixes its size.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
RAZOR
<div class="grid gap-6 md:grid-cols-2">
    <TwTextEditor Label="Grows up to 160px" Toolbar="TextEditorToolbar.Simple" MinHeight="80px" MaxHeight="160px" Value="@longHtml" />
    <TwTextEditor Label="Fixed at 120px" Toolbar="TextEditorToolbar.Simple" Height="120px" Value="@longHtml" />
</div>

Links

The link button, or Ctrl + K, opens a bar under the toolbar. Type an address and press Enter to link the selected text, or to insert the address as a link when nothing is selected. With the caret in a link, the bar changes or removes it. An address without a scheme gets https://, an email address gets mailto:, and an address such as javascript: is refused.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U) Strikethrough (Ctrl+Shift+X)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Link (Ctrl+K)
Press Alt+F10 to move to the toolbar.
RAZOR
<TwTextEditor Label="Links" MinHeight="80px" @bind-Value="linkHtml" />
CSHARP
@code {
    private string? linkHtml = "<p>Read the <a href=\"https://twblazor.com\">twblazor docs</a>, then select some text and press Ctrl + K.</p>";
}

Events and character count

OnTextChange receives the content as Html, plain Text and its Length, and OnSelectionChange the formats at the selection. OnFocus and OnBlur report focus. While the user types, changes are reported once typing pauses for DebounceInterval (250 milliseconds), and always when focus leaves the editor.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)

0 of 140 characters

Press Alt+F10 to move to the toolbar.

Formats at the caret: none

RAZOR
<TwTextEditor Label="Comment"
              Toolbar="TextEditorToolbar.Simple"
              MinHeight="80px"
              MaxHeight="200px"
              HelperText="@($"{commentLength} of {maxCommentLength} characters")"
              Invalid="@(commentLength > maxCommentLength)"
              ErrorMessage="@($"Keep your comment to {maxCommentLength} characters")"
              OnTextChange="@OnCommentChanged"
              OnSelectionChange="@OnCommentSelection"
              @bind-Value="commentHtml" />
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Formats at the caret: <strong>@commentFormats</strong></p>
CSHARP
@code {
    private const int maxCommentLength = 140;
    private string? commentHtml;
    private int commentLength;
    private string commentFormats = "none";
    
    private void OnCommentChanged(TextEditorChangeEventArgs change) => commentLength = change.Length;
    
    private void OnCommentSelection(TextEditorSelectionEventArgs selection) =>
        commentFormats = string.Join(", ", selection.Formats.Order());
}

Methods

Use @ref to call the editor from code: SetHtmlAsync and GetHtmlAsync, GetTextAsync and GetLengthAsync, FormatAsync, InsertLinkAsync and RemoveLinkAsync, UndoAsync, RedoAsync, ClearFormattingAsync and FocusAsync.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
Plain text appears here.
RAZOR
<div class="flex flex-col gap-3">
    <div class="flex flex-wrap gap-2">
        <TwButton Label="Load template" Variant="ButtonVariant.Outlined" OnClick="@LoadTemplateAsync" />
        <TwButton Label="Copy plain text" Variant="ButtonVariant.Outlined" OnClick="@ReadTextAsync" />
        <TwButton Label="Clear" Variant="ButtonVariant.Outlined" OnClick="@(() => methodsEditor!.SetHtmlAsync(null))" />
    </div>
    <TwTextEditor @ref="methodsEditor" Label="Letter" Toolbar="TextEditorToolbar.Simple" MinHeight="100px" />
    <pre class="rounded-md bg-black/5 p-3 text-xs whitespace-pre-wrap wrap-anywhere dark:bg-white/10">@methodsText</pre>
</div>
CSHARP
@code {
    private TwTextEditor? methodsEditor;
    private string methodsText = "Plain text appears here.";
    
    private Task LoadTemplateAsync() =>
        methodsEditor!.SetHtmlAsync("<p>Dear customer,</p><p>Thank you for your <strong>order</strong>.</p><p>Kind regards</p>");
    
    private async Task ReadTextAsync() => methodsText = await methodsEditor!.GetTextAsync();
}

Export

Set ExportFormats to add an export menu to the end of the toolbar, offering the formats in the order you list them, and ExportFileName for the saved file's name and the document's title. The formats are Markdown, Word (.docx), OpenDocument (.odt), a web page, plain text and Rich Text Format. Headings, lists, links, quotes and code blocks keep their meaning in each one: a Word document gets real heading styles and numbered lists. The files are written in .NET with no other package, and saved by the browser. Call ExportAsync to export from your own button; it also returns the file.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U) Strikethrough (Ctrl+Shift+X)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Quote (Ctrl+Shift+9) Code block
Link (Ctrl+K)
Clear formatting (Ctrl+\) Undo (Ctrl+Z) Redo (Ctrl+Y)
HTML source
Export
Press Alt+F10 to move to the toolbar.
RAZOR
<TwTextEditor Label="Meeting notes"
              Toolbar="TextEditorToolbar.Full"
              ExportFormats="@exportFormats"
              ExportFileName="Meeting notes"
              @bind-Value="exportHtml" />
CSHARP
@code {
    private readonly TextEditorExportFormat[] exportFormats =
    [
        TextEditorExportFormat.Docx,
        TextEditorExportFormat.Odt,
        TextEditorExportFormat.Markdown,
        TextEditorExportFormat.Html,
        TextEditorExportFormat.Rtf,
        TextEditorExportFormat.PlainText,
    ];
    
    private string? exportHtml = "<h1>Weekly sync</h1><p>Attendees: <strong>Ada</strong>, <strong>Grace</strong> and <em>Alan</em>.</p><h2>Actions</h2><ol><li>Ship the <a href=\"https://twblazor.com\">text editor</a></li><li>Write the release notes</li></ol><blockquote><p>Keep it simple.</p></blockquote>";
}

Converting on the server

TwTextEditorExport holds the same converters as static methods, so stored HTML can be turned into a file on the server, for example to email a document or to serve a download from an API: ToMarkdown, ToPlainText, ToHtmlDocument, ToRtf, ToDocx and ToOdt, or Export, which returns the bytes with a file name and media type. They read HTML with the editor's own rules, so HTML from anywhere converts safely.
Choose a format above.
RAZOR
<div class="flex flex-col gap-3">
    <div class="flex flex-wrap gap-2">
        <TwButton Label="Show Markdown" Variant="ButtonVariant.Outlined" OnClick="@(() => convertedText = TwTextEditorExport.ToMarkdown(exportHtml))" />
        <TwButton Label="Show plain text" Variant="ButtonVariant.Outlined" OnClick="@(() => convertedText = TwTextEditorExport.ToPlainText(exportHtml))" />
    </div>
    <pre class="rounded-md bg-black/5 p-3 text-xs whitespace-pre-wrap wrap-anywhere dark:bg-white/10">@convertedText</pre>
</div>
CSHARP
@code {
    private string convertedText = "Choose a format above.";
}

Context menu

Set ShowContextMenu to open a TwContextMenu of formatting actions on a right-click, or with Shift + F10 from the keyboard. It is off by default, since the browser's own menu holds spelling suggestions and the clipboard actions.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U) Strikethrough (Ctrl+Shift+X)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Link (Ctrl+K)
Press Alt+F10 to move to the toolbar.
RAZOR
<TwTextEditor Label="Right-click the text" ShowContextMenu MinHeight="80px" Value="@presetHtml" />

Validation

Inside an EditForm or a TwForm the editor reports every change, so validation attributes on the bound property run for it and their message is shown under the editor. An empty editor binds as an empty string, so [Required] works as it does for a text field.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U) Strikethrough (Ctrl+Shift+X)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Link (Ctrl+K)

Write at least a sentence.

Press Alt+F10 to move to the toolbar.
RAZOR
<EditForm Model="@article" class="flex flex-col gap-4">
    <DataAnnotationsValidator />
    <TwTextEditor Label="Article body" Required HelperText="Write at least a sentence." @bind-Value="article.Body" />
    <div>
        <TwButton Type="submit" Variant="ButtonVariant.Filled" Color="Color.Primary" Label="Publish" />
    </div>
</EditForm>
CSHARP
@code {
    private readonly ArticleModel article = new();
    
    private sealed class ArticleModel
    {
        [Required(ErrorMessage = "Write the article before publishing it")]
        public string? Body { get; set; }
    }
}

Variants

Variant works as it does on TwTextfield, so the editor lines up with the other inputs on a form.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
RAZOR
<div class="flex flex-col gap-6">
    <TwTextEditor Label="Outlined" Variant="InputVariant.Outlined" Toolbar="TextEditorToolbar.Simple" MinHeight="60px" />
    <TwTextEditor Label="Filled" Variant="InputVariant.Filled" Toolbar="TextEditorToolbar.Simple" MinHeight="60px" />
    <TwTextEditor Label="Default" Variant="InputVariant.Default" Toolbar="TextEditorToolbar.Simple" MinHeight="60px" />
</div>

Disabled and readonly

Disabled dims the editor and its toolbar, and it cannot be focused. ReadOnly keeps the text readable, selectable and in the Tab order, but it cannot be changed.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
Bold (Ctrl+B) Italic (Ctrl+I) Underline (Ctrl+U)
Bulleted list (Ctrl+Shift+8) Numbered list (Ctrl+Shift+7)
Press Alt+F10 to move to the toolbar.
RAZOR
<div class="grid gap-6 md:grid-cols-2">
    <TwTextEditor Label="Disabled" Toolbar="TextEditorToolbar.Simple" MinHeight="80px" Value="@presetHtml" Disabled />
    <TwTextEditor Label="Readonly" Toolbar="TextEditorToolbar.Simple" MinHeight="80px" Value="@presetHtml" ReadOnly />
</div>

Security

Everything that enters the editor, including a value set from code and pasted or dropped content, is rebuilt from the tags the editor supports, and a link keeps only an http, https, mailto, tel or relative address. Scripts, styles, images, event handlers and every other attribute are removed. This cleaning runs in the browser, so treat HTML posted to your server as untrusted and sanitize it again there, for example with a library such as HtmlSanitizer, before you store it or show it on another page.

Accessibility

The editing area is a multiline textbox named after the Label, with HelperText, any error message and a hint about the toolbar linked through aria-describedby. The toolbar is a toolbar named "Formatting": its toggle groups are each a single Tab stop with the arrow keys moving between their buttons, every button says whether its format is applied at the caret, and each one lists its shortcut in aria-keyshortcuts and its tooltip. Alt + F10 moves from the text to the toolbar, and a format applied from the toolbar with the keyboard leaves focus on the toolbar, so several can be applied in a row. Tab always leaves the editor rather than typing a tab character, so keyboard users are never trapped. All of the editor's own text is translated into the app's language.

Keyboard navigation

The text is a multiline text box, and the toolbar above it is one toolbar of groups: Tab moves from group to group, and the arrow keys move between the buttons in a group. Each button says whether its format is applied at the caret.
Key What it does
Tab or Shift+ plus Tab Moves focus into or out of the editor. Tab never types a tab character, so it always leaves the text.
Alt+ plus F10 In the text: moves focus to the toolbar.
Ctrl+ plus B or Ctrl+ plus I or Ctrl+ plus U Bold, italic or underline.
Ctrl+ plus Shift+ plus X Strikethrough.
Ctrl+ plus Shift+ plus 7 or Ctrl+ plus Shift+ plus 8 or Ctrl+ plus Shift+ plus 9 Numbered list, bulleted list or quote.
Ctrl+ plus Alt+ plus 0 or Ctrl+ plus Alt+ plus 1 or Ctrl+ plus Alt+ plus 2 or Ctrl+ plus Alt+ plus 3 Paragraph, or heading 1, 2 or 3.
Ctrl+ plus K Opens the link bar with focus in the address field.
Ctrl+ plus \ Clears bold, italic, underline, strikethrough and links from the selection.
Ctrl+ plus Z or Ctrl+ plus Y Undoes or redoes the last change.
Arrow Left or Arrow Right In a toolbar group: moves to the next or previous button. Reversed in a right to left layout.
Enter or Space On a toolbar button: applies or removes its format. Focus stays on the button.
Enter In the link address field: applies the link. Focus goes back to the text.
Escape In the link bar: closes it without changing anything, and returns focus to the text.
Shift+ plus F10 or Menu In the text, with ShowContextMenu set: opens the formatting menu.
Enter or Space or Arrow Down On the export button: opens the list of formats. The arrow keys move through it, and Enter saves the file in that format.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwTextEditorTheme), configured via the AddTwBlazor() options callback described on the Get Started page. Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
Property Type Controls
Root string
Disabled string
Toolbar string
ToolbarGroup string
ToolbarSeparator string
BlockSelect string
Content string
ContentDefaultVariant string
Typography string
LinkPanel string
LinkInput string
LinkInputField string
Source string
SourceInput string
HelperText string

Full reference: TwTextEditorTheme on the API docs.

On this page

  • Basic usage
  • Toolbar presets
  • No toolbar
  • Custom toolbar
  • Height
  • Links
  • Events and character count
  • Methods
  • Export
  • Converting on the server
  • Context menu
  • Validation
  • Variants
  • Disabled and readonly
  • Security
  • Accessibility
  • Keyboard navigation
  • Theme configuration
twblazor

The Tailwind CSS component library for Blazor. Accessible, themeable and MIT licensed.

Discord (opens in a new tab) GitHub(opens in a new tab)

Get started

  • Install guide
  • Theming
  • Class merging
  • Localization

Guides

  • Tailwind CSS with Blazor
  • Why twblazor?
  • Right to left
  • AI agents and skills

Resources

  • API documentation (opens in a new tab)
  • llms.txt (opens in a new tab)
  • MIT License (opens in a new tab)

Community

  • Contributing (opens in a new tab)
  • Code of conduct (opens in a new tab)
  • Report an issue (opens in a new tab)

twblazor is and always will be free and open source.

An unhandled error has occurred. Reload