Search code examples
htmltextarealine-breaks

How to add a new line in textarea element?


I want to add a newline in a textarea. I tried with \n and <br/> tag but are not working. You can see above the HTML code. Can you help me to insert a newline in a textarea?

<textarea cols='60' rows='8'>This is my statement one.\n This is my statement2</textarea>

<textarea cols='60' rows='8'>This is my statement one.<br/> This is my statement2</textarea>

Solution

  • Try this one:

        <textarea cols='60' rows='8'>This is my statement one.&#13;&#10;This is my statement2</textarea>

    &#10; Line Feed and &#13; Carriage Return are HTML entitieswikipedia. This way you are actually parsing the new line ("\n") rather than displaying it as text.