htmlcssline-breaks

Line break in HTML with '\n'


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

<div class="text">
  abc
  def
  ghi
</div>


Solution

  • 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>