How to preserve line breaks when getting text from a textarea with ... Regards, Arie.----- Line breaks actually are preserved, the target element is just set to ignore them while displaying the text but if you inspect it you will see they are here. html - Preserve line breaks in textarea - Stack Overflow To display line breaks from saved text area in a React component, we can set the white-space CSS property to pre-line. preserve line breaks in textarea javascript - elstyle.net convert - preserve line breaks in textarea javascript - Code Examples My jsp looks like this <textarea> line1=this_is_my_first_line . To preserve line breaks when getting text from a textarea with JavaScript, we can replace whitespace characters with '<br>\n'. How do I preserve line breaks when getting text from a textarea? Flexbox, Grid & Sass) convert - preserve line breaks in textarea javascript - Code Examples Please fix! keep line break in readonly textarea — oracle-tech In general you have to translate line break codes like \n to <br> tags. The white-space CSS property is helpful displaying the text in the same way it's provided by the user. This is because the textarea will be used to order food and the client doesn't want to receive a single line of text. Hi,I want to have a textarea as an input (like the contact form examples). // preserve line breaks ( \\ . const post = document.createElement ("p"); post.textContent = postText; post.innerHTML = post.innerHTML.replace (/\n/g, "<br>\n"); to call replace to replace all the \n characters with '<br>\n'.