Line breaks in HTML are '\n'
P粉470645222
2023-08-27 11:42:20
<p>Is there a way to get HTML to correctly handle <code>n</code> newlines? Or do I have to replace them with <code><br /></code>? </p>
<p><br /></p>
<pre class="brush:html;toolbar:false;"><div class="text">
abc
def
ghi
</div></pre>
<p><br /></p>
You can use the CSS
white-space
property to represent\n
. You can also keep tabs as shown in\t
.For newlines
\n
:For newlines
\n
and tabs\t
:This is to display line breaks and carriage returns in HTML. Then you don't need to do this explicitly. You can do this in CSS by setting the whitespace property pre-line value.