HTML entity encode/decode · Guide

HTML Entities Break Line: Newlines, <br> and &NewLine;

There is no HTML entity that breaks a line, and looking for one is a sign of a layout problem being approached from the wrong direction. Line breaks come from elements and CSS, not from character references.

Why an entity cannot do it

Entities produce characters, and HTML collapses whitespace characters — including newlines — into a single space when rendering. So even a real newline character in the source does not create a visible break.

&NewLine; exists in HTML5 and produces U+000A, an actual line feed. In normal flow content it is collapsed like any other whitespace and shows nothing. It only becomes visible inside <pre> or with white-space: pre applied.

What to use instead

HTML
<br>                              <!-- a break within a line of text -->
<p>First</p><p>Second</p>         <!-- separate paragraphs -->
<pre>line one
line two</pre>                    <!-- source newlines preserved -->
CSS
.preserve { white-space: pre-wrap; }   /* honour newlines, still wrap */

For user-submitted text, white-space: pre-wrap is usually better than converting newlines to <br> — it keeps the stored text clean and avoids injecting markup.

Converting newlines safely

If you do need <br> tags, escape first and convert second, so the conversion cannot introduce markup from user input:

PHP
echo nl2br(htmlspecialchars($text, ENT_QUOTES, 'UTF-8'));

Reversing that order lets a submitted <script> survive into the output. This ordering rule applies to any escape-then-transform pipeline.

The related entities

&nbsp; prevents a break rather than causing one — useful in 10&nbsp;kg or Fig.&nbsp;3. &shy; is a soft hyphen that only appears if the word actually wraps. <wbr> marks an optional break point in a long unbroken string such as a URL.

These control where breaks may happen. None of them force one.

Frequently asked questions

Is there an entity for a line break?

No. &NewLine; produces a newline character, which HTML collapses like any whitespace. Use <br> or CSS.

How do I preserve newlines from a textarea?

Apply white-space: pre-wrap, or escape the text and then convert newlines to <br>.

What does &nbsp; do?

It is a space that prevents a line break at that point — the opposite of causing one.

Ready to try it?

Open the free browser-based HTML entity encode/decode and apply what you just read — no sign-up, runs locally.

Open the HTML entity encode/decode tool