Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line in text inside div [duplicate]

Tags:

html

css

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) ?

like image 711
user3681138 Avatar asked Jul 25 '14 20:07

user3681138


People also ask

How do you put a line break in a div?

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.

How do you break a line in P tag?

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.

How do I put text on the next line in HTML?

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.

Does textarea support new line?

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.


1 Answers

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

like image 102
AstroCB Avatar answered Sep 24 '22 01:09

AstroCB