Security Tools

How to Encode and Decode HTML Entities Online

September 27, 2026

Written by Mohammad Sohail

HTML encoding converts characters that have special meaning in HTML — like <, >, and & — into safe text representations called entities. The browser displays them as literal characters instead of interpreting them as markup. Decoding reverses the process. It is the single most effective defense against cross-site scripting (XSS) attacks, and every developer who renders user content needs it.

When HTML Encoding Is Required

Displaying user-submitted comments or forum posts on a web page. Rendering search results that contain user query text. Building email templates that insert dynamic values. Storing rich text in a database that a CMS will escape on output. Logging error messages that contain code snippets. Anywhere untrusted text meets an HTML document.

Named vs Numeric Entities

Named entities are readable: &lt; for <, &gt; for >, &amp; for &, &quot; for double quote, &apos; for single quote. Numeric decimal references use the character code: &#60; for <. Numeric hexadecimal references use the hex code: &#x3C; for <. All three forms render the same character. Named entities are easier to read; numeric references work for any Unicode character, including emojis.

What I Tested

I used the HTML Encoder/Decoder with real-world payloads.

• XSS payload: '<script>alert("xss")</script>' → '&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;' — angle brackets and quotes fully escaped, payload neutralized. Correct.

• '&copy; 2026 &mdash; All rights reserved' decoded → '© 2026 — All rights reserved'. All named entities resolved correctly.

• '5 &lt; 10 &amp;&amp; 10 &gt; 3' decoded → '5 < 10 && 10 > 3'. Nested ampersands handled correctly.

• Numeric input '&#60;b&#62;Bold&#60;/b&#62;' decoded → '<b>Bold</b>'. Numeric references round-trip correctly.

Step-by-Step

(1) Open the HTML Encoder/Decoder. (2) Paste your HTML or plain text in the input area. (3) Click 'Encode' to convert special characters to entities, or 'Decode' to reverse. (4) Copy the result to your clipboard.

Limitation

Encoding only covers HTML context. If your text goes into a JavaScript string, a URL parameter, or a CSS value, HTML entities will not protect it — you need URL encoding for query strings or proper JavaScript string escaping for scripts. For attribute values, review complex cases manually.

Common Mistake

Double-encoding. If input already contains entities ('&amp;lt;') and you encode again, & becomes &amp;amp; — the output shows '&amp;lt;' literally instead of '<'. Always decode once first to check if the input is already encoded, then encode exactly once.

How It Compares

htmlencoder.org requires a page reload and only supports one-way encoding. W3Schools has an entity reference but no interactive encoder. Browser DevTools work but require console access. Our tool does bidirectional encode/decode in one interface, handles numeric character references, and processes everything locally with no upload.

Related Encoding Guides

If you also handle query strings, read the URL encoding guide for percent-encoding rules and the double-encoding trap. For binary data like images and files converted to text, see the Base64 guide. To strip leftover HTML tags from scraped text entirely, use the Text Cleaner.

Privacy: Your text is processed entirely in your browser using JavaScript. It is never sent to any server. No one at FreeDigitalToolkit can see your content.

Next Step: Encoding prevents XSS — but weak passwords are a separate risk. Check yours with the Password Strength Checker, and inspect API tokens safely with the JWT Decoder.

The Five Characters That Actually Matter

Five characters carry the risk. The less-than and greater-than signs open and close tags, so they become &lt; and &gt;. The ampersand starts every entity and therefore has to be written as &amp; first — if you skip that step, &amp;lt; turns into the wrong character. Quotes matter inside attributes: &quot; for double quotes and &#39; for single quotes keep the attribute boundary where the author put it.

Everything else — accented letters, emoji, the rest of the punctuation — can pass through unescaped, which is why encoders leave it alone. Encoding the whole document would make the source unreadable for no gain; the goal is to neutralise the five that can change the meaning of the markup.

Where Encoding Happens Automatically

Most template engines escape by default, so putting a user's name inside a variable in React, Vue, Razor or a server-side template usually needs no manual work — and deliberately turning escaping off is where sites get into trouble. Content management systems escape most fields too, though HTML editors that accept markup do not, because their whole purpose is to keep the tags.

Manual encoding is needed when you assemble markup by hand: building an attribute value from user input, generating a download filename that contains a title, sending an HTML email with a dynamic subject line, or writing the value into a JavaScript string that will become innerHTML later. In each of those places the text crosses from data into markup, and that is where the entities belong.

Frequently Asked Questions

What is the difference between HTML encoding and URL encoding?

They solve different problems. HTML encoding replaces characters that would otherwise be read as markup — angle brackets, ampersands, quotes — so the text displays instead of executing. URL encoding replaces characters that are not legal in a URL, turning a space into %20 and an ampersand into %26 so the address stays valid.

Will encoded text look wrong to the people reading the page?

No. A browser converts the entities back before rendering, so visitors see the characters, not the codes. Only the page source shows &amp; or &#39;, which is exactly the point — the source stays unambiguous while the display stays readable.

Do I need to encode single quotes as well?

Only inside a single-quoted attribute, and only if the text itself contains a single quote. In HTML5 &apos; is valid; &#39; works everywhere and is what most encoders emit. Double-quoted attributes need the double-quote entity instead, and the two cases are the source of most broken forms.

Is my text sent anywhere when I encode it?

No. Encoding happens in your browser tab on the text in front of you. Nothing is transmitted or stored.

Try it yourself

Open Tool →