HTML Display line breaks within textarea

user1260310 picture user1260310 · Nov 21, 2012 · Viewed 77.1k times · Source

I have asked this question now several ways, but still have not gotten an answer.

When you capture asci text in a textarea that includes line breaks, it seems to insert invisible characters in the form of line breaks when you hit return. The line break seems to have the format \r for return or \n for new line. These characters are not visible in the text but are there somewhere.

However, when I put this code in a textarea, I cannot get it to display a linebreak. In fact, I cannot find any code that placed between textarea tags displays a line break.

Can someone show a way to display line breaks in a textarea, ie.

<textarea>first line <some code> second line </textarea>

I have really tried about everything you could possibly imagine. For example, if I try <textarea> first line "\r\n" second line</textarea> it just displays

`firstline "\r\n"` second line

Note: anything involving <br> will not solve this problem as this is not about html, but rather plain text displaying in textarea box.

Thanks for suggested code to display line breaks in textarea.

Answer

Jeremy Morehouse picture Jeremy Morehouse · Nov 21, 2012

Well if you're doing this through pure HTML, then you can do it one of two ways. Just add lines by pressing enter or using the ASCII characters &#013; &#010;

jsFiddle