Skip to content

HTML Entity Encoder and Decoder

Paste text to escape the characters that break HTML, or paste escaped markup to turn the entities back into readable characters.

Runs in your browserFree, no sign-upLast reviewed

Settings

Minimal keeps text readable; extended also escapes non-ASCII characters.

Results update automatically as you type.

Encoded HTML

<a href="/docs?a=1&b=2">Tom & Jerry's "guide"</a>

The five characters that must be escaped

CharacterEntityWhy
&&Starts every entity, so it must be escaped first
<&lt;Opens a tag
>&gt;Closes a tag
"&quot;Ends a double-quoted attribute value
'&#39;Ends a single-quoted attribute value

Quick answers

Which characters need to be escaped in HTML?
Five: & as &amp;, < as &lt;, > as &gt;, the double quote as &quot; and the apostrophe as &#39;. The ampersand and angle brackets matter in text; the two quote marks matter inside attribute values.
What does &amp; mean in HTML?
&amp; is the entity for a literal ampersand. Because every entity starts with &, a real ampersand in text or in a URL inside an attribute is written as &amp; so the browser does not try to read what follows as an entity name.
What are &lt; and &gt;?
&lt; is the less-than sign < and &gt; is the greater-than sign >. Writing them as entities makes the browser display the characters instead of treating them as the start and end of a tag, which is how you show code such as <div> on a page.
How do I decode HTML entities back to text?
Switch Mode to Decode, paste the escaped text and read the Decoded text panel. For example &lt;p class=&quot;note&quot;&gt;Tom &amp; Jerry&#39;s&lt;/p&gt; decodes to <p class="note">Tom & Jerry's</p>, shrinking from 63 characters to 33.
Why does my page show &amp;amp; or &amp;lt;?
The text was escaped twice. The second pass escaped the ampersand that the first pass created, so &lt; became &amp;lt; and the browser now shows &lt; as literal text. Decode once per extra layer, then remove the duplicate escaping step from your pipeline.
Is &#39; the same as &apos;?
Both produce an apostrophe. &#39; is a numeric reference that works in every HTML version and in XML. &apos; is a named entity defined in XML and HTML5 but not in HTML 4, so the encoder here outputs &#39;. The decoder accepts both.

What HTML Entity Encoder & Decoder does

This tool converts in both directions. In Encode mode it replaces the five characters that have a special meaning in HTML: & becomes &amp;, < becomes &lt;, > becomes &gt;, the double quote becomes &quot; and the apostrophe becomes &#39;. Everything else is left alone unless you choose the extended option, which also writes every non-ASCII character as a decimal reference such as &#233; for é. In Decode mode it resolves every decimal and hexadecimal reference plus 20 of the most common named entities. Each run peels off exactly one layer, which makes it easy to see when text has been escaped twice.

HTML entity codes chart: named, decimal and hex

These are the 20 named entities the decoder recognises, with the numeric forms that refer to the same character. Decimal and hex references for any other Unicode character are decoded too.

CharacterNamed entityDecimalHexDescription
&&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
(space)&nbsp;&#160;&#xA0;Non-breaking space
©&copy;&#169;&#xA9;Copyright sign
®&reg;&#174;&#xAE;Registered sign
™&trade;&#8482;&#x2122;Trade mark sign
…&hellip;&#8230;&#x2026;Ellipsis
—&mdash;&#8212;&#x2014;Em dash
–&ndash;&#8211;&#x2013;En dash
‘&lsquo;&#8216;&#x2018;Left single quote
’&rsquo;&#8217;&#x2019;Right single quote
“&ldquo;&#8220;&#x201C;Left double quote
”&rdquo;&#8221;&#x201D;Right double quote
é&eacute;&#233;&#xE9;e with acute accent
€&euro;&#8364;&#x20AC;Euro sign
£&pound;&#163;&#xA3;Pound sign
°&deg;&#176;&#xB0;Degree sign

Other named entities, such as &hearts;, &times; and &rarr;, are left unchanged by the decoder. Use their numeric form if you need them resolved here.

Encoding examples: escaping HTML so it displays as text

Each result below is the exact output of the tool for the input shown.

A link with a query string and quotes (the default sample)

<a href="/docs?a=1&b=2">Tom & Jerry's "guide"</a>

&lt;a href=&quot;/docs?a=1&amp;b=2&quot;&gt;Tom &amp; Jerry&#39;s &quot;guide&quot;&lt;/a&gt;

All five unsafe characters appear in this one line, so it is a good test of any escaping routine.

A script tag you want to show, not run

<script>alert("hi")</script>

&lt;script&gt;alert(&quot;hi&quot;)&lt;/script&gt;

A code condition inside a paragraph

if (a < b && c > d) { print("ok"); }

if (a &lt; b &amp;&amp; c &gt; d) { print(&quot;ok&quot;); }

Accents, symbols and emoji with Unsafe plus all non-ASCII

Café © 2026 — 5 € ☕ 😀

Caf&#233; &#169; 2026 &#8212; 5 &#8364; &#9749; &#128512;

With Only HTML-unsafe characters selected, the same input comes back unchanged because it contains none of the five.

Encoding text that is already encoded

AT&amp;T

AT&amp;amp;T

The encoder does not detect existing entities. Encode raw text only, or you create the double-encoding problem described below.

Decoding examples, including double-encoded text

Escaped comparison from a database field

5 &lt; 10 &amp;&amp; 10 &gt; 5

5 < 10 && 10 > 5

The Summary panel reports 30 characters in and 16 out.

One extra layer

&amp;lt;b&amp;gt;

&lt;b&gt;

The output is still escaped, which tells you the source was encoded twice. Decode it again to reach <b>.

Two extra layers

&amp;amp;lt;b&amp;amp;gt;

&amp;lt;b&amp;gt;

Three passes are needed in total, so three stages in the pipeline are escaping where one should.

Mixed named, decimal and hex references

&copy; &#169; &#xA9; &#128512; &#x1F600;

© © © 😀 😀

Why the ampersand must be escaped first

Every entity begins with an ampersand, so the ampersand is the one character whose order matters. If a routine replaced < with &lt; first and then replaced every & with &amp;, the ampersand it had just written would be escaped too, giving &amp;lt;. The browser would then display the five characters &lt; instead of a less-than sign.

The same mechanism explains double encoding in real systems. A template engine escapes a value, a later stage escapes the already safe string again, and each pass adds one more amp; to every entity. Three passes turn a quote into &amp;amp;quot;. Decoding one layer at a time, as this tool does, shows you how many stages are involved, which is usually one more than you intended.

What this encoder and decoder does not do

  • Encoding never produces named entities beyond the five. Extended mode writes decimal references such as &#169;, not &copy;, and there is no hex output option.
  • Named entities are matched without regard to case, so &Eacute; decodes to lowercase é. Use &#201; when you need the capital É.
  • An entity needs its closing semicolon to be decoded. &lt without the semicolon is left as typed.
  • Hex references are recognised with a lowercase x only. &#x41; decodes to A, while &#X41; is left as typed.
  • Entity encoding protects text placed in HTML content or a quoted attribute. Text going into a script block, a URL or a CSS value needs the escaping rules of that context instead.
  • Nothing is sent to a server. Both directions run in your browser, so pasting content from a database or a support ticket does not transmit it.

Step by step

  1. 1

    Set Mode to Encode — text to entities, or to Decode — entities to text.

  2. 2

    Paste your text or markup into the Input box, replacing the sample link.

  3. 3

    When encoding, choose Only HTML-unsafe characters to keep accents and emoji readable, or Unsafe plus all non-ASCII to turn those into numeric references as well.

  4. 4

    Copy the Encoded HTML or the Decoded text from the result panel.

  5. 5

    If decoded output still contains entities, paste it back in and decode again. Each pass removes one layer.

Answers to common questions

Does escaping HTML prevent XSS?
Escaping the five unsafe characters is the main defence when untrusted text is inserted into HTML content or a quoted attribute, because the text can no longer open a tag or close the attribute. It is not sufficient in other contexts: values placed inside a script block, an event handler, a URL or a style need their own escaping.
Should I encode accented letters and emoji?
Usually not. On a page served as UTF-8 they display correctly as typed and keep the source readable. The Unsafe plus all non-ASCII option is for systems where the character encoding is uncertain, such as older email templates or a legacy database column, where a numeric reference survives intact.
What is the difference between a named entity and a numeric reference?
A named entity uses a word, such as &copy;, and exists only for characters that were given a name. A numeric reference uses the Unicode code point in decimal (&#169;) or hexadecimal (&#xA9;) and works for any character. All three forms display the same symbol.
Do I need to escape > and quotes in normal text?
Strictly, only & and < must be escaped in text content, and the quote that matches the surrounding delimiter must be escaped inside an attribute value. Escaping all five everywhere is the common practice because one rule is then safe in both positions.
How do I show HTML code on a web page?
Encode the snippet first, then paste the result inside a pre or code element. The browser turns &lt;div&gt; back into the visible text <div> when it renders the page, so readers see the markup instead of the browser acting on it.
Is HTML encoding the same as URL encoding?
No. HTML encoding writes characters as entities such as &amp; so they are safe inside markup. URL encoding writes them as percent sequences such as %26 so they are safe inside a URL. A query string placed in an href needs both: percent-encode the values, then write the & separators as &amp;. The site's URL Encoder handles the percent step.
Why did some entities not decode?
The decoder resolves all decimal and hex references but only the 20 named entities listed in the chart above. Anything else, for example &hearts; or &middot;, passes through untouched, as does any entity missing its semicolon.

Looking for something else? Browse all developer tools or see every tool.