Skip to content
AgileLogics

HTML Encoder / Decoder

Encodes reserved characters (&, <, >, ", ') into their HTML entity equivalents, or decodes HTML entities back to plain text.

Working on a whole file? Open it in the HTML editor →

How it works

Type or paste text, choose a direction, and click Convert.

What does an HTML encoder do?

An HTML encoder replaces characters that have a special meaning in HTML with entity references, so a browser shows them as text instead of reading them as markup. This tool escapes the five characters that matter, &, <, >, " and '. Its decode mode runs the other way, turning entities such as &lt;, &copy; or &#8364; back into the characters they stand for.

The five escapes

Character Encoded as Why it needs escaping
& &amp; Starts every entity, so a bare one can be misread
< &lt; Starts a tag
> &gt; Ends a tag
" &quot; Ends a double-quoted attribute value
' &#39; Ends a single-quoted attribute value

The ampersand is replaced first. If it weren't, the & inside a freshly made &lt; would itself get escaped.

Worked example. Encoding this snippet:

<a href="/x?a=1&b=2">Tom's</a>

gives:

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

Paste that into a page and readers see the original tag as text, which is what you want for code samples, tutorials and showing user input back to the user. The & inside the URL is escaped too; inside an href attribute, &amp; is the correct way to write a literal ampersand anyway.

Encoding text for a page

  1. Choose Encode in the Direction menu.
  2. Paste the text or code you want to show literally.
  3. Click Convert and copy the result into your HTML.

Characters outside those five are not turned into entities. © café € comes out unchanged. That's deliberate and safe for any page served as UTF-8 with a <meta charset="utf-8"> declaration, which is the default for HTML today. Converting every accented letter to &eacute; makes the source harder to read without changing what the browser displays.

How decoding works

Decode mode hands your text to the browser's HTML parser in a context where tags aren't built, so only character references are converted. That has some useful consequences:

  • Every entity in the standard works. The full list of named references is in the WHATWG HTML named character references table. &copy; 2026 &mdash; &euro;5 decodes to © 2026 — €5.
  • Numeric references work in both bases. &#169;, &#xA9; and &copy; all decode to ©, and &#x1F44D; gives 👍.
  • Tags stay as text. <b>bold</b> &amp; <script>x</script> decodes to <b>bold</b> & <script>x</script>. Nothing is rendered or executed, and the tags aren't stripped either.
  • Only one layer is removed. &amp;lt; decodes to &lt;, not to a bare less-than sign. Text that was escaped twice needs decoding twice.

One behaviour catches people out. For compatibility with old pages, browsers recognise some entity names even without the closing semicolon. &copy decodes to ©, and &amp to &. The side effect is that an unknown name beginning with a known one is partly decoded: &notit; becomes ¬it;, because &not is the "not sign" entity. If decoded output contains a stray ¬, © or similar, look for a malformed entity in the source.

&nbsp; decodes to a real no-break space (U+00A0), not an ordinary space, so it can still break exact-match comparisons after decoding.

Where encoding fits in security

Escaping these five characters is the standard defence for untrusted data placed in HTML element content and in quoted attribute values. It isn't enough in other contexts. Inside a <script> block, an event handler, a URL or CSS, an attacker doesn't need < or " to cause trouble. The OWASP XSS Prevention Cheat Sheet lays out the right encoding for each context.

In application code, use your framework's built-in escaping rather than pasting output from a tool. Most do the same job as this encoder:

Language Function Single quote becomes
PHP 8.1+ htmlspecialchars() &#039;
Python html.escape() &#x27;
This tool Encode &#39;

All three spellings of the single quote are equivalent to a browser.

Related tools

The HTML viewer renders markup so you can see the difference between encoded and raw HTML. If you're putting text into a URL rather than a page, use the URL encoder, and for strings inside JSON, the JSON escape tool. The HTML cheat sheet covers the surrounding syntax.

Last updated

Frequently asked questions

Which characters does the HTML encoder convert?
Exactly five: & becomes &amp;, < becomes &lt;, > becomes &gt;, a double quote becomes &quot; and a single quote becomes &#39;. Everything else, including accented letters, symbols like © and emoji, is left as it is.
Why does &amp; turn into &amp;amp; when I encode it?
Encode mode treats your input as plain text, so the & at the start of &amp; is escaped like any other ampersand. That's correct if you want the page to display the literal text &amp;. If your input is already encoded, don't encode it again.
Which entities can the decoder handle?
All of them. Decoding uses the browser's own HTML parser, so every named character reference in the HTML standard works (&copy;, &mdash;, &euro;, &nbsp; and the rest), along with decimal references like &#169; and hex ones like &#xA9;.
Is it safe to decode HTML that contains script tags?
Yes. The decoder only converts entity references to characters. Tags in the input are kept as literal text and nothing is run, so <script> comes out as the text <script>.
Is HTML encoding enough to prevent XSS?
Only in HTML text and quoted attribute values. Data placed inside JavaScript, URLs or CSS needs the escaping rules for that context. OWASP's XSS Prevention Cheat Sheet explains which encoding each context needs.