Rich text editor’s newline behaviour has been changed, now generates <div> instead of <br>

Published: | Categories: DOM HTML


In Firefox, hitting the Enter key on a rich text editor inserts a <br> element, while Internet Explorer generates <p> and Google Chrome adds <div>. After much discussion, Firefox 60 changes the behaviour to match Chrome, so <div> will be used as the new default separator.

If you type “Firefox” and hit Enter between “Fire” and “fox”, the result HTML would be <div>Fire</div><div>fox</div> instead of Fire<br>fox.

This behaviour, already enabled by default on Firefox Nightly and early Beta/DevEdition since version 55, can be controlled using the DefaultParagraphSeparator command for the execCommand method.

// To insert <br> as before
document.execCommand("DefaultParagraphSeparator", false, "br");
// To generate <p> instead
document.execCommand("DefaultParagraphSeparator", false, "p");