Named, decimal & hexDouble-encoding detectionNothing dropped silently

HTML Entity Encoder & Decoder

Escape markup characters as named, decimal or hexadecimal entities, or decode entities back to the characters they represent. All processing happens locally in your browser.

HTML escaping

Escape markup characters or turn entities back into text

Encoding replaces characters that would otherwise be parsed as markup. Decoding resolves named, decimal and hexadecimal references back to the characters they stand for.

Input characters
Characters escaped
Output characters
Size change
Encoding options
Numeric references work everywhere; named references are easier to read.
Escaping only markup characters keeps accented text readable in the source.
InputText or markup
OutputEscaped source

The escaped source appears here as you type.

Only the characters selected above are replaced. Everything else is passed through byte for byte.

Load sampleLoad text to escape

What is an HTML entity?

An HTML entity is a stand-in for a character, written so the browser stores the character without treating it as markup. Every entity starts with & and ends with ;.

The problem it solves: HTML uses < to start a tag and & to start an entity. If your content genuinely contains those characters, the parser cannot tell your text apart from your markup.

Write this in a page:

<p>5 < 10</p>

and the browser sees < 10</p> as the start of a tag. Escape the comparison operator and the meaning is unambiguous:

<p>5 &lt; 10</p>

The page still displays 5 < 10. Only the source changed.

The five characters that matter

Long lists of entities exist, but only five characters can actually change how markup is parsed:

Character Named Decimal Hex Why it needs escaping
& &amp; &#38; &#x26; Starts every entity, so it must be escaped first
< &lt; &#60; &#x3C; Opens a tag
> &gt; &#62; &#x3E; Closes a tag
" &quot; &#34; &#x22; Ends a double-quoted attribute value
' &#39; &#39; &#x27; Ends a single-quoted attribute value

Order matters when escaping. & has to go first, otherwise escaping < to &lt; and then escaping ampersands turns it into &amp;lt;. This tool handles all five in a single pass, so that ordering bug cannot occur.

On the apostrophe: &apos; is valid in XML and HTML5 but was never part of HTML 4. &#39; works everywhere, so that is what the named style outputs for '.

How to encode or decode entities

  1. Choose a direction Encode turns characters into references. Decode turns references back into characters.
  2. Pick a reference style when encoding Named produces &copy;, decimal produces &#169;, hexadecimal produces &#xA9;. All three render identically.
  3. Choose what to escape “Markup characters only” touches the five above and leaves accented letters as readable text. “Markup plus all non-ASCII” escapes anything above code point 127 as well, which is useful for systems stuck on a legacy character encoding.
  4. Check the counters When encoding you see how many characters were replaced and how much the output grew. When decoding you see how many named, decimal and hex references were found and resolved.

Named vs numeric references

Both forms point at the same character. The difference is legibility versus universality.

Examples of the same character in all three styles

Character Named Decimal Hexadecimal
© &copy; &#169; &#xA9;
&mdash; &#8212; &#x2014;
&euro; &#8364; &#x20AC;
é &eacute; &#233; &#xE9;
Non-breaking space &nbsp; &#160; &#xA0;
🙂 (no name) &#128578; &#x1F642;

Named references only exist for a fixed vocabulary. Emoji, most CJK characters and rarer symbols have no name at all, which is why the encoder falls back to a numeric reference automatically whenever no name applies.

The hexadecimal form is the one to reach for when working from a Unicode chart: U+2014 becomes &#x2014; with no arithmetic. The decimal form requires converting 2014 from hex to 8212 first.

Double encoding, and how to recognise it

Double encoding is the most common entity bug. It happens when a string that is already escaped gets escaped again — usually because both a template engine and application code decided to be careful.

Original:        <b>bold</b>
Escaped once:    &lt;b&gt;bold&lt;/b&gt;
Escaped twice:   &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;

On the page, a double-escaped string displays as the literal text &lt;b&gt;bold&lt;/b&gt; — visible entity codes instead of either bold text or the tags. That symptom, entities showing up in rendered output, always points at one escape too many somewhere in the chain.

This page flags input that matches the pattern &amp; followed by another entity name, and you can send the output back to the input to peel off one layer at a time until the text is clean.

Entities are not the same as URL encoding

Both replace characters, but they apply to different layers and use different syntax. Mixing them up produces broken links.

HTML entities Percent encoding
Applies to Text inside an HTML document Text inside a URL
Syntax &name; or &#nn; % plus two hex digits
A space becomes Unchanged (or &nbsp; when non-breaking) %20
An ampersand becomes &amp; %26

A URL inside an href attribute can need both, in this order: percent-encode the query values, then entity-escape the resulting string for the attribute. So ?a=1&b=2 is written href="?a=1&amp;b=2" in the source. Use the URL Encoder & Decoder for the percent-encoding half.

Use cases

  • Publishing code in an article. Any HTML example shown as text has to be escaped, or the browser renders it instead of displaying it.
  • Reading an escaped API response. Feeds and CMS exports frequently return &lt;p&gt; where you expected markup. Decode to see the real content.
  • Auditing what a sanitiser did. Compare input and output to confirm the five markup characters were handled and nothing extra was mangled.
  • Fixing entities that leaked into visible text. Decode the affected string to identify how many escape layers were applied.
  • Preparing content for a legacy pipeline. Escaping all non-ASCII characters as numeric references keeps text intact through systems that are not reliably UTF-8.
  • Finding invisible characters. Encoding non-ASCII reveals a non-breaking space as &#160; and a zero-width space as &#8203;, both of which are invisible in an editor.

Privacy and a security caveat

Encoding and decoding are string operations performed in your browser; the text is not uploaded to convert it.

Important: escaping is context-sensitive, so this tool is a debugging and authoring aid, not an XSS defence. Escaping the five markup characters is correct for HTML text nodes and quoted attribute values. It is not sufficient inside a <script> block, inside a style attribute, or in an unquoted attribute. Production applications should rely on their framework's context-aware output escaping.

Frequently Asked Questions

Do I have to escape every accented character?

No. On a UTF-8 page you can write é, €, 中 and emoji directly, and that is the normal modern choice because the source stays readable. Escaping non-ASCII characters is only worth doing when content must survive a pipeline whose character encoding you do not control.

Why does &nbsp; behave differently from a normal space?

  is U+00A0, a distinct character from the ordinary space at U+0020. Browsers never collapse or line-break on it, which is what makes it useful for keeping "10 kg" together, and also what makes it a nuisance when it gets pasted invisibly into content and breaks a string comparison.

Which reference style should I use?

Named for the common few — &lt;, &gt;, &amp;, &quot;, &nbsp;, &copy;, &mdash; — because they are self-documenting. Hexadecimal when you are working from a Unicode code point, since U+2014 maps straight to —. Decimal mainly when a legacy system requires it.

Why does decoding leave some entities untouched?

Unrecognised names are preserved rather than deleted, and they are listed under the output so you can see what was skipped. This also matters for genuine text: in "Fish & Chips &co", the &co is not a valid reference, so it stays exactly as written.

Does decoding here strip HTML tags?

No. Decoding only rewrites entity references and leaves everything else byte for byte, so real tags in your input survive. That is deliberate — tools that decode by parsing the string as HTML silently discard the markup around the entities.

Is escaping these five characters enough to stop XSS?

Only for HTML text and quoted attribute values. Different contexts need different escaping: JavaScript string literals, CSS values, unquoted attributes and URL attributes each have their own rules. Use your framework's context-aware escaping in production and treat this page as a debugging tool.

What is the difference between an entity and a Unicode code point?

The code point is the character's number in the Unicode standard, written U+00E9 for é. An entity is one way to write that number inside an HTML document, as é or é or é. The code point is the identity; the entity is the transport syntax.