HTML Entity Encoder and Decoder

Escape text or HTML code as entities so it shows up as written on a web page, or turn entities like & and ' back into readable characters. Choose which characters to encode and whether to write them as named, decimal, or hex entities. Everything runs in your browser.

Plain text or HTML
Characters to encode
Entity format
Encoded HTML
Encoded HTML

What are HTML entities?

An HTML entity is a code that stands for one character. It starts with an ampersand and ends with a semicolon, like &lt; for < or &copy; for ©. The browser shows the character, not the code.

Entities exist because some characters mean something to HTML. A < starts a tag and an & starts an entity, so if you want a page to show them as text, you have to write them as &lt; and &amp;. Encoding does that for you. Decoding goes the other way and turns the codes back into characters.

Why use our HTML entity encoder

  • ·Free. No signup, no paywall, no limits.
  • ·Runs in your browser. Your text is never uploaded.
  • ·Three entity formats. Named, decimal, or hex, with a choice of how many characters to escape.
  • ·Decodes every entity. It uses the browser's own HTML parser, so all HTML5 names and numeric references work.
  • ·Emoji safe. Emoji and other characters outside the basic range become a single correct reference, not two broken halves.

HTML entity encoder options

Only HTML characters

Escapes only the five characters HTML reads as markup: &, <, >, and the two quote marks. Everything else, including accents and emoji, stays as it is. This is what you need to show code or user text on a web page.

Before<b>"Hi" & bye</b>After&lt;b&gt;&quot;Hi&quot; &amp; bye&lt;/b&gt;

HTML characters and non-ASCII

Also escapes every character outside plain ASCII: accented letters, symbols like © and €, emoji, and invisible ones like the non-breaking space. Use it when the page or file might not be saved as UTF-8.

Beforecafé © 😀Aftercaf&eacute; &copy; &#128512;

All characters

The default. Escapes every character except spaces, tabs, and line breaks, so even plain letters and digits become numeric references. The text looks the same in a browser but is unreadable in the source.

Beforea@b.coAfter&#97;&#64;&#98;&#46;&#99;&#111;

Named entities

Writes characters by name where one exists, like &eacute; or &copy;. Names are easier to read in source code. The tool uses the 252 names from HTML 4, which every browser supports. A character without one of those names is written as a decimal reference instead.

Beforeé © 😀After&eacute; &copy; &#128512;

Decimal entities

Writes each character as its Unicode code point in decimal, like &#233;. Every character has one, so the output is consistent, and it works in both HTML and XML.

Beforeé © 😀After&#233; &#169; &#128512;

Hexadecimal entities

Writes the code point in hex, like &#xE9;. The number matches the U+ code you see in character tables (U+00E9), which makes it easy to look a character up.

Beforeé © 😀After&#xE9; &#xA9; &#x1F600;

Encode quotes

On by default. Escapes " and ' so the text is safe inside an attribute value. Turn it off to keep quotes readable when the text only goes between tags, where quotes are allowed as they are.

Beforesay "hi"Aftersay &quot;hi&quot;

How to encode and decode HTML entities

  1. 1

    Pick Encode or Decode

    Choose Encode to turn text or HTML code into entities, or Decode to turn entities back into readable characters.

  2. 2

    Set the encode options

    When encoding, choose which characters to escape and whether to write them as named, decimal, or hex entities. Turn off Encode quotes if the text only goes between tags.

  3. 3

    Convert and copy

    Type or paste your text, click Encode or Decode, then copy the result or download it as a .txt file.

Common HTML entities and their codes

These are the entities you will run into most. Each column gives the same character, so you can use whichever form you prefer.

CharacterNamedDecimalHexWhat it is
&&amp;&#38;&#x26;Ampersand
<&lt;&#60;&#x3C;Less-than sign
>&gt;&#62;&#x3E;Greater-than sign
"&quot;&#34;&#x22;Double quote
'&apos;&#39;&#x27;Apostrophe (single quote)
(space)&nbsp;&#160;&#xA0;Non-breaking space
©&copy;&#169;&#xA9;Copyright sign
®&reg;&#174;&#xAE;Registered sign
™&trade;&#8482;&#x2122;Trademark sign
€&euro;&#8364;&#x20AC;Euro sign
£&pound;&#163;&#xA3;Pound sign
–&ndash;&#8211;&#x2013;En dash
…&hellip;&#8230;&#x2026;Ellipsis
→&rarr;&#8594;&#x2192;Right arrow
×&times;&#215;&#xD7;Multiplication sign

&apos; is valid in HTML5 and XML but was not part of HTML 4, so this tool writes an apostrophe as &#39; even in named mode. Both decode to the same character.

Which characters you need to escape in HTML

You do not have to escape every symbol. What needs escaping depends on where the text goes:

  • ·Text between tags. Escape & and <. Escaping > is not strictly required, but it is common practice and does no harm. Quotes can stay as they are.
  • ·Inside an attribute value. Escape & and the quote mark that wraps the value, so a " inside title="..." becomes &quot;.
  • ·Accents, symbols, and emoji. No escaping is needed if the page is saved as UTF-8 and has a <meta charset="utf-8"> tag, which is the default for modern sites. Use "HTML characters and non-ASCII" for older systems, or for email templates and files where the encoding might change along the way.

Only HTML characters escapes all five markup characters, which is safe in both text and attributes, and leaves the rest of your text readable.

Fixing double-encoded HTML entities like &amp;amp;

If a page shows &amp;, &quot;, or &#39; where you expected &, ", or ', the text was escaped twice. The first pass turned & into &amp;. A second pass then escaped the ampersand at the start of that entity, giving &amp;amp;, which the browser shows as the literal text &amp;.

To clean up the text, paste it into the tool on Decode and decode it once. If it was escaped more than twice, paste the result back in and decode again until it reads correctly. To stop it happening again, look for the place where text that is already escaped gets escaped a second time, such as a template that escapes a value your code has already encoded.

How to escape HTML in JavaScript and Python

When you need to do this in code instead of by hand, these do the same job as the Only HTML characters setting above.

Encode HTML entities in JavaScriptJavaScript
function escapeHtml(text) {
  return text
    .replaceAll("&", "&amp;")
    .replaceAll("<", "&lt;")
    .replaceAll(">", "&gt;")
    .replaceAll('"', "&quot;")
    .replaceAll("'", "&#39;");
}

escapeHtml(`<p class="note">Tom & Jerry's</p>`);
// "&lt;p class=&quot;note&quot;&gt;Tom &amp; Jerry&#39;s&lt;/p&gt;"
Decode HTML entities in the browserJavaScript
function decodeHtml(text) {
  const textarea = document.createElement("textarea");
  textarea.innerHTML = text;
  return textarea.value;
}

decodeHtml("caf&eacute; &copy; &#128512;");
// "café © 😀"
Encode and decode with Python's html modulePython
import html

html.escape("<p class=\"note\">Tom & Jerry's</p>")
# '&lt;p class=&quot;note&quot;&gt;Tom &amp; Jerry&#x27;s&lt;/p&gt;'

html.unescape("caf&eacute; &copy; &#128512;")
# 'café © 😀'

Python's html.escape writes an apostrophe as &#x27; (the hex form) rather than &#39;. Both mean the same character.

When to encode HTML entities

  • ·Showing code on a web page. Escape an HTML snippet before you put it in a blog post or a <pre> block, so readers see the tags instead of the browser running them.
  • ·Putting text in an attribute. Escape quotes in a title, alt text, or data attribute so they do not end the value early.
  • ·Reading scraped or exported data. Decode text from an API, RSS feed, or database export that is full of &amp; and &#39;.
  • ·Email templates. Encode accents and symbols as entities so they show correctly in mail clients that get the encoding wrong.
  • ·Hiding an email address in page source. "All characters" turns an address into numeric references that look normal on the page. It stops only the simplest scrapers, since many decode entities first.

Frequently asked questions

What are HTML entities?
An HTML entity is a short code that stands for a character, written between an ampersand and a semicolon. &lt; stands for <, &amp; stands for &, and &copy; stands for ©. Browsers show the character instead of the code. You use them for characters that HTML would otherwise read as markup, and for characters that are hard to type or might not survive a change of file encoding.
How do I encode text as HTML entities?
Leave the tool on Encode, choose which characters to escape and which entity format to use, then paste your text and click Encode. For showing code or user text on a page, choose Only HTML characters so the rest of your text stays readable in the source.
How do I decode HTML entities back to text?
Click Decode, paste text that contains entities such as &amp;, &quot;, or &#39;, and click the Decode button. Every named, decimal, and hex entity is turned back into its character. Tags in the input are left as plain text, so nothing is removed.
Which characters have to be escaped in HTML?
In text between tags, always escape & and <, and escape > too by habit. Inside an attribute value, also escape the quote mark that wraps the value: " inside double quotes, ' inside single quotes. Only HTML characters escapes all five, which is safe in both places.
What is the difference between named, decimal, and hex entities?
They all produce the same character. A named entity uses a word (&eacute;), a decimal one uses the Unicode number (&#233;), and a hex one uses the same number in hexadecimal (&#xE9;). Named entities are easier to read but only exist for some characters. Decimal and hex work for every character, including emoji.
Why does my page show &amp; or &quot; instead of & or a quote mark?
The text was encoded twice. The first pass turned & into &amp;, and the second pass escaped the ampersand at the start of that entity again, giving &amp;amp;. To fix the text, decode it once to remove the extra layer. To fix the cause, find the step in your code or CMS that escapes text that was already escaped.
Why does named mode write &#39; instead of &apos; for an apostrophe?
&apos; was not part of HTML 4, so some older browsers and email clients do not recognize it. &#39; means the same thing and works in every version of HTML and in XML. The decoder reads both.
Does escaping HTML stop XSS attacks?
Escaping &, <, >, ", and ' is the standard defense when you put untrusted text between tags or inside a quoted attribute. It is not enough in other places: inside a <script> or <style> block, in an unquoted attribute, or in a link like href="javascript:...". Use your framework's built-in escaping, and treat this tool as a way to check or prepare text by hand.
Does the decoder understand every HTML entity?
Yes. Decoding uses your browser's own HTML parser, so it knows all of the more than 2,000 named entities in HTML5, decimal and hex references, and older forms like &copy written without the semicolon. The result matches what a browser would show for the same text.
Is my text private?
Yes. Encoding and decoding run in your browser, and nothing you type or paste is sent to a server.