HTML code for line break

The HTML code for line break is <br>

for example:

line one of the text <br>
Next line <br>
Another line.

Paragraphs

If you want to separate a block of text into paragraphs, then the right tag to use is the paragraph tag (<p>).

<p>
A paragraph of text. Another line.
</p>

<p>
Next paragraph and all its text
</p>

Demo

22934

Using CSS option " white-space: pre-line "

If you want a block of text with exact line breaks, then the right solution would be to use the CSS style white-space:pre-line

CSS

.prelined
{
  white-space: pre-line;
}

HTML

<div class="prelined">
  This is a     line     of    text
  Another Line of text
  Yet another line
  and so on 
</div>

Notice that we didn’t put <br> in each line. The new lines in the text is followed while rendering for that block.

Demo

22934

Close

Copy and paste this code to display the image on your site

Copied!