Skip to main content

Control what Enter does in an ASP.NET Core rich text editor

The editor with a formatted document

By default, Enter starts a new paragraph. Some systems need something else, such as an email tool that wants line breaks. The enter-key-tag attribute sets it.

The three options

<richtextbox name="A" toolbar="basic" enter-key-tag="p" height="150px"></richtextbox>
<richtextbox name="B" toolbar="basic" enter-key-tag="div" height="150px"></richtextbox>
<richtextbox name="C" toolbar="basic" enter-key-tag="br" height="150px"></richtextbox>
ValueSaved asUse it when
p<p>One</p><p>Two</p>Almost always. Real paragraphs
div<div>One</div><div>Two</div>Your layout or system expects blocks without paragraph margins
brOne<br>TwoOutput goes somewhere that treats text as lines

Why p is the right default

Paragraphs carry meaning for screen readers, and your CSS can space them. People who ask for br often only want less space between lines. You can do that with CSS and keep real paragraphs:

.article p { margin: 0 0 .5rem; }

A line break inside a paragraph

Whichever you choose, Shift+Enter inserts a single line break. That suits an address or a poem.

Set it before you have content

This setting affects what people type from now on, and it does not rewrite documents already saved. A site that changes it later will have both forms in its database.

Read next