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) ?
Basic HTML Line Break Syntax You can insert line breaks in HTML with the <br> tag, which is equivalent to a carriage return on a keyboard.
Most programs and online forms support the Shift + Enter keyboard shortcut. To use this shortcut, move to the text cursor to where you want the new line to begin. Then, press and hold the Shift key, and press the Enter key.
In HTML, the <br> element creates a line break. You can add it wherever you want text to end on the current line and resume on the next.
The P element renders all contiguous white spaces (including new lines) as one space. The LF character does not render to a new line or line break in HTML. The TEXTAREA renders LF as a new line inside the text area box.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With