30

In a textarea, there are new lines using for example 
, but how can I do this to a div element without using htmll (plain text like \n) ?

user3681138
  • 337
  • 1
  • 3
  • 9

1 Answers1

83

You can use CSS to force HTML to recognize new lines as line breaks.

Just set the white-space property to pre:

div {
    white-space: pre;
}

Demo

AstroCB
  • 12,337
  • 20
  • 57
  • 73