Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line break in HTML with '\n'

Tags:

html

Is there a way to make HTML properly treat \n line breaks? Or I have to replace them with <br/>?

<div class="text">   abc   def   ghi </div>
like image 397
stkvtflw Avatar asked Sep 05 '16 07:09

stkvtflw


People also ask

What does \n do in HTML?

The \n character matches newline characters.

What is \n line break?

Newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in a character encoding specification (e.g., ASCII, EBCDIC) that is used to signify the end of a line of text and the start of a new one.

How do I make a line break in HTML?

The <br> tag inserts a single line break. The <br> tag is useful for writing addresses or poems. The <br> tag is an empty tag which means that it has no end tag.


1 Answers

This is to show new line and return carriage in HTML, then you don't need to do it explicitly. You can do it in CSS by setting the white-space attribute pre-line value.

<span style="white-space: pre-line">@Model.CommentText</span> 
like image 155
khakishoiab Avatar answered Oct 06 '22 07:10

khakishoiab