Skip to content

HTML Entity Encoder & Decoder

Escape characters that would break HTML into entities, or decode entities back into readable text.

Runs in your browserFree, no sign-up

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

What HTML Entity Encoder & Decoder does

Five characters cannot be dropped into HTML as-is without changing what the markup means: the ampersand, the angle brackets and both quote marks. This tool escapes them into entities so the browser renders them as text rather than treating them as syntax, and decodes in the other direction when you need to read content that has already been escaped — sometimes escaped twice, which is where the confusing &amp;lt; sequences come from. Encoding runs in your browser, so you can safely paste content from a database or a user submission while you work out what is happening to it.

What people use it for

Showing code samples on a page

Displaying HTML markup as text requires escaping it first, otherwise the browser renders the example instead of showing it.

Tracking down double-encoded text

When users see &amp;amp; on a page, something escaped already-escaped text. Decoding step by step shows how many layers were applied.

Preparing content for an email template

Email clients are far less forgiving than browsers, and escaping unusual characters avoids layouts breaking in older desktop clients.

Cleaning up scraped or exported content

Text pulled out of a CMS or an RSS feed often arrives escaped. Decoding restores readable prose before you edit it.

Step by step

  1. 1

    Choose whether you are encoding text into entities or decoding entities back into text.

  2. 2

    Paste the text or markup into the input box.

  3. 3

    For encoding, decide whether to escape only the HTML-unsafe characters or also every non-ASCII character.

  4. 4

    Copy the result. When decoding, run it twice if the output still contains entities — that indicates double encoding.

Why the ampersand has to be escaped first

Every entity begins with an ampersand, which makes the ampersand itself the character that has to be handled before any other. If you escaped the angle brackets first and the ampersands afterwards, the ampersand that you just introduced at the start of &lt; would be escaped in turn, producing &amp;lt; — and the browser would then render the literal text &lt; rather than a less-than sign. This ordering requirement is the mechanical reason double-encoded text is so common: any pipeline where one stage escapes and a later stage escapes again produces exactly this result, and each additional pass adds another amp; layer. When you see a page displaying &amp;amp;quot;, you are looking at three passes. Decoding repeatedly until the output stops changing tells you how many stages in your pipeline are doing the work, which is usually one more than intended.

Named entities, numeric references, and when to use each

There are two ways to write any entity. A named reference such as &copy; is readable but only works for characters that have an assigned name, and the set of valid names depends on the HTML version. A numeric reference such as &#169; or its hexadecimal form &#xA9; works for any character in Unicode and is understood everywhere, at the cost of being unreadable in source. The practical rule is that named entities are worth using for the handful you recognise on sight, and numeric references are the safe default for everything else. There is one specific trap: &apos; for the apostrophe is defined in XML and HTML5 but not in HTML 4, so &#39; is the safer choice in templates and email where the parsing mode is uncertain. For ordinary accented letters and emoji on a UTF-8 page, no escaping is needed at all — writing them literally is both correct and far easier to read.

Tips

  • On a UTF-8 page, leave accented characters and emoji unescaped; the extended mode is for legacy systems with uncertain encoding.
  • If decoded output still contains entities, decode again — each pass peels off one layer of encoding.
  • Escaping is context-sensitive: text going into a URL, a script block or a CSS value needs its own escaping rules, not HTML entities.

Answers to common questions

Which characters actually need escaping in HTML?
Five: the ampersand, less-than, greater-than and both quote marks. The ampersand must be escaped first, otherwise escaping the others would produce broken double-encoded entities such as &amp;lt;.
Does escaping HTML prevent XSS?
Escaping these characters is the core defence when inserting untrusted text into HTML, but context matters — text placed inside a script block, a URL attribute or a style needs its own escaping rules rather than HTML entity encoding.
What is the difference between &#39; and &apos;?
Both represent an apostrophe. &#39; is a numeric reference that works everywhere including older HTML, while &apos; is an XML/HTML5 named entity that is not recognised in HTML 4, so the numeric form is the safer default.
Should I encode non-ASCII characters like é or emoji?
Not usually. On a page served as UTF-8 they display correctly as-is and stay readable in the source. Extended encoding is mainly useful for legacy systems or email templates with uncertain encoding.

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