Skip to main content

Customize the rich text editor toolbar in ASP.NET Core

A short custom toolbar with a few groups of buttons

A comment box does not need sixty buttons. A short toolbar is easier to use, and it keeps people from producing content that does not fit your site. In RichTextBox, the toolbar attribute takes a preset name or your own list.

The presets

<richtextbox name="Body" toolbar="default"></richtextbox>
PresetGood for
basicComments and short text: bold, italic, link, image, emoji
defaultMost editing, with tables, files, find and the review tools
fullThe longest list, adding the gallery, footnotes, merge fields and table menus
mobile, officeA phone-sized toolbar, and an Office-style one

Your own list

Name the buttons you want, in groups:

<richtextbox name="Body"
             toolbar="{bold,italic,underline}|{fontname,fontsize}|{forecolor,backcolor}|{insertlink,insertimage}|{undo,redo}"
             height="300px"></richtextbox>

Names people look for

You wantName
Bold, italic, underline, strikethroughbold, italic, underline, strike
Headings and paragraph styleparagraphs
Font, size, coloursfontname, fontsize, forecolor, backcolor
Lists, checklistinsertorderedlist, insertunorderedlist, inserttodolist
Link, picture, galleryinsertlink, unlink, insertimage, insertgallery
Video, file, table, code blockinsertvideo, insertdocument, inserttable, insertcode
Find, HTML source, full screenfind, code, fullscreenenter
Clear formatting, format painterremoveformat, formatpainter
Word and PDFimportdocument, exportdocx, exportpdf

The toolbar reference lists them all.

Different toolbars for different people

The value can come from your code:

<richtextbox asp-for="Body"
             toolbar="@(User.IsInRole("Editor") ? "full" : "basic")"></richtextbox>

Removing a button makes the editor simpler, but it is not security. Someone can still paste any HTML or post your form by hand. To control what is stored, clean the HTML on the server, and to control who can upload, use a policy.

Read next