When to Use HTML Entities, and When Plain UTF-8 Is Better

Understand what HTML entities are, which five characters must be escaped, when named or numeric codes help, and how to fix double-encoded text like &.

Updated September 29, 2026 6 min read

Use the free HTML Entity Encoder / DecoderEncode or decode HTML entities like & and ©

You paste a product description into a CMS and the page shows Terms &amp; Conditions instead of "Terms & Conditions". A code sample in a blog post disappears because the browser treated <div> as a real tag. A price with a currency symbol turns into a question mark in an old email template. All three problems come down to the same thing: how special characters are written inside HTML.

This guide explains what HTML entities are, which characters genuinely need escaping, when named or numeric codes are worth using, and how to untangle text that has been encoded twice. It also shows how to convert text both ways in your browser.

What an HTML entity is

An HTML entity is a way of writing a character using only plain ASCII. It starts with an ampersand and ends with a semicolon:

  • Named entities use a memorable name: &copy; for ©, &mdash; for —, &eacute; for é.
  • Decimal numeric references use the character's Unicode code point: &#169; for ©.
  • Hexadecimal numeric references use the same code point in hex: &#xA9; for ©.

All three produce the same character on screen. Named entities are easier to read in source code, but only a fixed set of characters has a name. Numeric references work for any Unicode character, including those without a name, such as the Indian rupee sign, which is &#8377;.

The characters you must escape

Modern web pages are almost always saved as UTF-8, which can represent every character directly. That means you rarely need entities for accented letters, symbols or emoji. What you do need to escape are characters that HTML itself treats as syntax:

Character Entity Why it matters
< &lt; Starts a tag
> &gt; Ends a tag (escaping it avoids confusion)
& &amp; Starts an entity
" &quot; Ends a double-quoted attribute value
' &#39; or &apos; Ends a single-quoted attribute value

Escaping these five is also a basic defence against cross-site scripting when you insert user-supplied text into a page. If someone types <script> into a comment box and it is escaped, the browser displays the text instead of running it. Proper frameworks do this automatically; the problems arise when content is assembled by hand or copied between systems.

When entities still earn their place

Even on a UTF-8 site, there are practical reasons to use entities:

  • Invisible or look-alike characters. A non-breaking space (&nbsp;) or a soft hyphen is impossible to see in source code. Writing it as an entity makes intent obvious to the next person editing the file.
  • Showing code on a page. To display <button> literally in a tutorial, it has to be written as &lt;button&gt;.
  • Systems with uncertain encoding. Older email templates, legacy CMS fields and some XML feeds may not declare UTF-8 correctly. Numeric references survive any encoding because they are pure ASCII.
  • Attributes. Quotes inside title or alt attributes must be escaped, or the attribute ends early.

Encode or decode text in your browser

The HTML Entity Encoder / Decoder converts text both ways without sending it anywhere.

  1. Open the HTML Entity Encoder / Decoder and choose Encode or Decode at the top.
  2. Paste your content into the input box. Sample loads an example with a rupee price, an ampersand, quotes and a copyright sign; Clear empties the box.
  3. When encoding, choose an Entity format: Named (©), Decimal (©) or Hex (©). In named mode, characters without a common name fall back to decimal codes.
  4. Decide whether to switch on Also encode non-ASCII characters (₹, é, emoji…). Leave it off if your page is UTF-8 and you only want the five syntax characters escaped; turn it on for ASCII-only destinations.
  5. Copy the result from Encoded output or Decoded output. The character counts underneath show how much longer the encoded version is.
  6. Click Swap to move the output back into the input and flip the mode, which is a quick way to check a round trip.

Below the converter, the Common HTML entities reference table lists characters with their named and numeric forms. Search it, and click a row to copy the entity.

Decoding uses the browser's own HTML parser in an inert text area, so it recognises every standard named entity and numeric reference without running any scripts in the text.

Other ways to escape HTML

In code

Most languages have a built-in function, and it is usually the right choice inside an application:

import html
html.escape('Price < 100 & "free"')   # 'Price &lt; 100 &amp; &quot;free&quot;'
html.unescape('&copy; 2026')          # '© 2026'

In PHP, htmlspecialchars() escapes the syntax characters. Template engines such as those in React, Django or Laravel escape output by default, so you rarely need to do it manually there.

In an editor

Code editors often have extensions or commands that escape a selection. A find-and-replace also works for a one-off fix, but always replace & first, otherwise you will re-escape the ampersands you just created.

A browser tool is quicker for one-off snippets, emails and CMS fields; in code, use the language's own function so escaping happens every time.

Troubleshooting encoded text

Double encoding (&amp;amp;, &amp;lt;)

This happens when already-escaped text is escaped again, often when content passes through two systems. Decode it once, check the result, and decode again if entities remain. Then find which system is escaping text that it should be storing as plain characters.

Question marks or strange symbols

Characters like é instead of é usually mean the text was saved in UTF-8 but read as another encoding, or the reverse. Entities can work around it, but the real fix is a <meta charset="utf-8"> declaration and consistent file encoding.

Entities in URLs

Entities are for HTML, not URLs. Inside an href, an ampersand between query parameters should be written as &amp; in the HTML source, but the characters in the URL itself need percent-encoding. Use a URL encoder for that, and see the Base64 converter if you need to embed binary data rather than text.

Entities in JSON or JavaScript strings

JSON has its own escaping rules (\", \n, é). HTML entities inside JSON are just literal text. The String Escape tool handles those formats.

Frequently asked questions

What is the difference between &nbsp; and a normal space?

A non-breaking space looks the same but prevents a line break at that point and is not collapsed with neighbouring spaces. Use it between a number and its unit, for example 10&nbsp;kg.

Do I need to encode accented letters like é?

Not on a page served as UTF-8, which is the modern default. Encode them only when the destination may not handle UTF-8 correctly.

Is &apos; valid in HTML?

It is defined in HTML5 and XML, but some older HTML parsers did not recognise it. &#39; is the most compatible way to write an apostrophe.

Why do some characters have no named entity?

Named entities cover a fixed list defined by the HTML standard. Any other character can still be written as a decimal or hex numeric reference using its Unicode code point.

Does escaping HTML make my site secure?

Escaping user input before inserting it into HTML is one important protection against cross-site scripting, but it is not the whole picture. Attributes, URLs and scripts each need the right escaping for their context.

Try it now: HTML Entity Encoder / Decoder

Loading tool…