Upload a file
  1. base64hub
  2. Web & token tools
  3. HTML entities

HTML Entities Encoder and Decoder

Escape &, <, > and quotes so text is safe inside HTML, or unescape &amp;, &eacute; and &#x2014; back to the characters they stand for.

Free no sign-up, no limits Local nothing uploaded HTML5 every named entity decoded by the browser parser Updated Oct 27, 2026
Input 0Output 0

Processed in your browser. This page cannot send your data anywhere – how we know

How to escape or unescape HTML

  1. Choose Escape or Unescape.
  2. For escaping, pick what to escape under Escape:
    • Only & < > " ‘ for HTML you will paste into a page or template.
    • Plus all non-ASCII for pages, emails or systems that are not UTF-8 safe.
    • Every character to encode all text, for testing parsers.
  3. Pick the Format: Named (é), Decimal (é) or Hex (é). Named falls back to decimal for characters that have no common name. Untick Escape quotes if the text only goes into element content.
  4. Copy output. Swap moves the result to the other side for a round-trip check.

Unescaping uses the browser’s HTML parser, so every one of the more than 2,000 named references in HTML5 is supported, along with decimal and hex references. The input is never rendered as HTML.

Common entities

CharacterNamedDecimalHex
&&amp;&#38;&#x26;
<&lt;&#60;&#x3C;
>&gt;&#62;&#x3E;
"&quot;&#34;&#x22;
'&apos; (HTML5)&#39;&#x27;
non-breaking space&nbsp;&#160;&#xA0;
é&eacute;&#233;&#xE9;
—&mdash;&#8212;&#x2014;
€&euro;&#8364;&#x20AC;
©&copy;&#169;&#xA9;
😀none&#128512;&#x1F600;

Numeric references use the Unicode code point. The emoji takes four bytes in UTF-8 but only one reference.

Pitfalls when escaping and decoding

  • Escape & first. Replacing < with &lt; and then & with &amp; produces &amp;lt;. Any hand-written escaper must handle & before the others.
  • Unencoded & in text can turn into a symbol. HTML still recognizes some legacy entities without a semicolon, so the text ?id=1&copy=2&para=3 displays as ?id=1©=2¶=3. Write &amp; for every ampersand, in URLs too.
  • Double escaping shows up as &amp;lt;b&amp;gt; on the page. Unescape once, then find which layer escapes twice.
  • &nbsp; is not a space. It decodes to U+00A0, which looks like a space but fails string comparisons and trim() in some languages.
  • Entities are not URL encoding. In a link, &amp; separates query parameters in the HTML source, while %26 is a literal ampersand inside a value. The URL encoder handles the second.

Escaping and unescaping in code

import html
html.escape('5 > 3 & "quotes"')    # '5 &gt; 3 &amp; &quot;quotes&quot;'
html.unescape("Caf&eacute; &#x2014; &copy;")   # 'Café — ©'
const escapeHtml = s => s.replace(/&/g, "&amp;").replace(/</g, "&lt;")
  .replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");

const unescapeHtml = s =>
  new DOMParser().parseFromString(s, "text/html").documentElement.textContent;

Python’s html.escape escapes quotes by default and writes ' as &#x27;. PHP’s htmlspecialchars() is the usual choice there; since PHP 8.1 it escapes both quote types by default. DOMParser does not run scripts in the parsed document, which makes it a safe way to decode in the browser. For more JavaScript string handling see the JavaScript page.

Entities, Base64 and data URIs

HTML entities and Base64 solve different problems. Entities make characters safe inside HTML source; Base64 turns bytes into text so a whole file fits into an attribute. To embed a complete HTML document in a data: URI or a JSON field, encode it with HTML to Base64 instead of escaping every character.

FAQ

Which characters must be escaped in HTML?

In text content, & and <, and > by convention. Inside attribute values also the quote that delimits the value, " or '. Everything else, including accented letters and emoji, can stay as is in a UTF-8 page.

What is the difference between &#39; and &apos;?

Both mean the apostrophe. &apos; is defined in HTML5 and XML but was missing from HTML 4, so &#39; is the form that works in every parser and email client. The escaper here uses &#39;.

Why do I see &amp;amp; on my page?

The text was escaped twice: & became &amp;, and a second pass turned that into &amp;amp;. Unescape once here to get the intended text, and remove the extra escaping step, usually a template engine escaping a value that was already escaped.

Does escaping HTML entities prevent XSS?

It prevents injection into HTML text and quoted attribute values. It does not make data safe inside <script> blocks, javascript: URLs, CSS or unquoted attributes; those contexts need their own encoding. Prefer your template engine’s auto-escaping.