HTML entity encode/decode · Guide

What Are HTML Entities and Why Are They Used?

An HTML entity is a way of writing a character using only ASCII text, starting with `&` and ending with `;`. They exist for two reasons, and only one of them still matters much today.

The two original reasons

Escaping structure. Some characters mean something to the HTML parser, so writing them literally changes the document. < starts a tag, & starts an entity — to display them as text you must escape them.

Representing unavailable characters. In the days of ASCII-only editors and ambiguous encodings, &copy; was the reliable way to write ©. With UTF-8 everywhere, this reason has largely disappeared.

The five that matter

These are the ones that break markup or enable cross-site scripting if left raw:

HTML
&   &amp;      <   &lt;      >   &gt;
"   &quot;     '   &#39;   (&apos; is HTML5 only)

Escape order matters when doing it by hand: replace & first, or you re-escape the ampersands you just inserted and produce &amp;lt;.

Named versus numeric

Named entities are readable — &rarr;, &nbsp;, &copy; — but only exist for characters that were given a name. There are over 2,000 in HTML5, and you will use about thirty.

Numeric references work for every character: decimal &#8594; or hexadecimal &#x2192;, both giving →. When no name exists, this is the only option.

When to skip them entirely

With <meta charset="utf-8"> declared, you can type →, ©, é and emoji directly in the source. That is more readable than an entity and renders identically.

So the practical rule: always escape the five structural characters, use entities for invisible characters such as &nbsp; where the intent would otherwise be invisible in the source, and type everything else literally.

And escape on output rather than storing escaped text — a database full of &amp; breaks every non-HTML consumer of that data.

Frequently asked questions

Do I still need HTML entities with UTF-8?

Only for the five structural characters and invisible ones like &nbsp;. Everything else can be typed directly.

Named or numeric?

Named where one exists and readability helps; numeric always works and covers every character.

Why does a semicolon matter?

Entities are terminated by it. Browsers may recover from a missing one, but decoders will not.

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