Line break in HTML with '\n'

stkvtflw picture stkvtflw · Sep 5, 2016 · Viewed 524.8k times · Source

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

https://jsfiddle.net/zawyatzt/

Answer

khakishoiab picture khakishoiab · Sep 5, 2016

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>