Use a textarea element instead of a contentEditable element: (emphasis mine)
The textarea element represents a multiline plain text edit
control for the element's raw value.
Example:
/* Auto resize height */
var textarea = document.querySelector('textarea');
(textarea.oninput = function() {
textarea.style.height = 0;
textarea.style.height = textarea.scrollHeight + 'px';
})();
textarea { width: 100%; }