DEVELOPER TOOL

HTML Encoder Decoder — entity converter

Convert special characters to HTML entities or decode HTML entities back to plain text, instantly.

Switch direction any time — the input label updates automatically.
Works on raw text, HTML snippets, or user-generated content.
Output
Tom & Jerry...
Ready
0
Input chars
0
Output chars
0
Chars escaped
0
Entities used
Tip: always encode untrusted user input before inserting it into HTML to prevent cross-site scripting (XSS).

The HTML encoder decoder tool converts the characters that have special meaning in HTML — &, <, >, ", and ' — into their safe entity equivalents, and reverses the process to turn encoded entities back into readable text. It is one of the most frequently reached-for utilities in front-end and back-end development, because getting HTML escaping wrong is one of the most common causes of both broken page rendering and real security vulnerabilities.

This converter does two jobs and states its limits plainly: it escapes the five markup-significant characters, optionally turns characters above the basic ASCII range into numeric entities, and decodes numeric entities plus a short list of common named ones. Whatever you paste stays in your browser tab.

What This HTML Encoder Decoder Tool Does

In encode mode, this tool scans your input text and replaces the five HTML-significant characters with their named entity equivalents: & becomes &amp;, < becomes &lt;, > becomes &gt;, " becomes &quot;, and ' becomes &#39;. This is exactly the transformation a browser needs so that raw text — including text a user typed, which might accidentally or maliciously contain HTML syntax — displays as literal characters on the page instead of being interpreted as markup.

In decode mode, the tool does the reverse. It converts every decimal and hexadecimal numeric entity (&#38;, &#x26;) and these eleven named ones: &amp;, &lt;, &gt;, &quot;, &apos;, &nbsp; (to a non-breaking space), &copy;, &reg;, &mdash;, &ndash; and &hellip;. Any other named entity, such as &eacute; or &euro;, is left exactly as typed. Decoding runs one level only, so &amp;lt; becomes &lt;, not <.

There is also an optional mode that encodes every character above the basic ASCII range as a numeric entity, which is useful when you need output that is pure ASCII, such as for older systems, certain email clients, or XML pipelines that don't reliably handle raw UTF-8 bytes. It works one Unicode code point at a time, so accented letters come out as one entity (é becomes &#233;) and so do emoji and other characters outside the Basic Multilingual Plane (😀 becomes &#128512;).

How to Use It

  1. Choose a mode. Select "Encode" to escape special characters, or "Decode" to convert entities back to readable text.
  2. Paste your content. Drop in raw text, a snippet of HTML, or user-submitted content.
  3. Set non-ASCII handling if needed. Turn on numeric-entity encoding for non-English characters if your target system requires pure ASCII output.
  4. Review the result. The converted text appears instantly, along with the input and output character counts, how many characters were escaped, and how many entities the output contains.
  5. Copy and use it. Click "Copy Result" and paste the safe or decoded text into your code, CMS, or email template.

How HTML Entity Encoding Works

HTML entities exist because a handful of characters carry structural meaning in HTML markup. The browser's parser treats < and > as the start and end of a tag, & as the start of an entity reference, and quote characters as the boundaries of an attribute value. If any of these characters appear literally inside text that's meant to be displayed — rather than interpreted as markup — the parser can misread the structure of the page, breaking layout or, worse, allowing injected script to execute.

An entity reference is simply a reserved sequence that the parser recognizes and converts back into the literal character at render time: a named form like &amp;, or a numeric form like &#38; (decimal) or &#x26; (hexadecimal), both of which reference the character's Unicode code point. Because the parser treats these sequences specially and never confuses them with real markup, they are the correct, standards-based way to include a literal <, >, or & in visible page content. The definitive reference for named character references is maintained by the WHATWG HTML Living Standard, and MDN's HTML entity glossary is a good practical companion.

Why This Matters for Security: HTML Escaping and XSS

Beyond visual correctness, HTML escaping is a core defense against cross-site scripting (XSS), one of the most common web application vulnerabilities. XSS happens when an attacker manages to get their own HTML or JavaScript rendered as part of a trusted page — for example, by submitting a comment containing <script> tags that a vulnerable site inserts directly into the page without escaping. If the site instead HTML-encodes that user input before rendering it — turning < into &lt; — the browser displays the literal text of the comment instead of executing it as a script.

The OWASP Cross Site Scripting Prevention Cheat Sheet says the protection depends on how the data is used: prefer safe APIs that treat data as text, use context-specific output encoding where data enters a context that interprets syntax, and use a maintained HTML sanitizer when you must accept user-authored HTML. It adds that input validation does not replace these protections. Hence HTML encoding is context-specific: text placed inside an HTML element body needs HTML entity encoding, but text placed inside a JavaScript string, a URL, or a CSS value needs different encoding rules entirely. Using this tool to HTML-encode a value before dropping it into a <script> block, for instance, will not make it safe. That requires JavaScript string escaping instead.

Named vs. Numeric Entities

HTML supports two entity styles. Named entities like &amp;, &lt;, &copy;, and &nbsp; are human-readable shorthands defined in the HTML specification, but only the names on the specification's list are recognized. Numeric entities like &#169; (decimal) or &#xA9; (hexadecimal) reference any Unicode code point directly and work universally, even for characters that have no named shorthand, such as emoji or rare symbols. This tool's "encode all non-ASCII as numeric entities" option uses this numeric form, so it does not depend on a name existing. It does have the emoji limit described above, because it counts UTF-16 code units rather than whole characters.

How to Read the Result

  • The big line shows the first 60 characters of the output. The full result is in the box underneath.
  • Input chars and Output chars count UTF-16 code units, not bytes, so an emoji counts as 2.
  • In encode mode, Chars escaped is how many input characters were replaced, and Entities used is how many entities the output contains. They match unless the input already held entity-like text.
  • In decode mode both tiles show the same number: the entity-like sequences found in the input. That includes names the decoder does not know, which are counted but left unchanged, so compare input and output to see what really changed.

Results from the tool for typical inputs:

Mode and inputOutputIn / out / escaped / entities
Encode, the sample text on this pageCafé menu: 5 &lt; 10 &amp; 3 &gt; 2, &quot;quoted&quot; &amp; &#39;apostrophe&#39; &lt;tag attr=&quot;x&quot;&gt;65 / 113 / 12 / 12
Same sample with non-ASCII encoding onSame, with Caf&#233;65 / 118 / 13 / 13
Encode <script>alert("x")</script>&lt;script&gt;alert(&quot;x&quot;)&lt;/script&gt;27 / 49 / 6 / 6
Encode &amp; &lt; (already encoded)&amp;amp; &amp;lt; (double-encoded)10 / 18 / 2 / 2
Encode Hi 😀 café with non-ASCII encoding onHi &#128512; caf&#233; (one entity per character)10 / 22 / 2 / 2
Decode Tom &amp; Jerry &lt;b&gt; &copy; &#169; &#xA9; &eacute; &euro; &nbsp;|Tom & Jerry <b> © © © &eacute; &euro; plus a non-breaking space and |70 / 40 / 9 / 9
Decode Caf&eacute; &amp;lt;Caf&eacute; &lt;20 / 16 / 2 / 2

What to Do Next

  1. Check for stray entities in the output before pasting. If you see &amp;amp;, the text was encoded twice.
  2. Decide the context first. HTML text and quoted attributes take entity encoding; URLs, such as the values in a link, take percent-encoding from the URL encoder decoder.
  3. Emoji in ASCII-only output come out as a single numeric entity, such as &#128512;.
  4. For user-submitted content in a real application, escape in your template layer or framework, not by pasting output from a page like this one.
Building something bigger than a converter?

Arb Digital builds websites and web apps. This converter is one of the free tools on this site; if you need escaping handled properly inside a real application, we can help.

Talk to Arb Digital All Free Tools

Common Mistakes to Avoid

  • Encoding in the wrong context. HTML entity encoding protects HTML element content and attributes, not JavaScript strings, URLs, or CSS — each context needs its own escaping rules.
  • Expecting the decoder to know every name. Only eleven named entities are decoded here, so &eacute; stays as typed. Numeric entities always decode.
  • Double-encoding. Running already-encoded text through the encoder again turns &amp; into &amp;amp;, corrupting the display. Always decode first if you're unsure of the current state.
  • Relying on client-side encoding alone for security. XSS defenses must happen on the server (or in the rendering layer) for any content that reaches other users — client-side encoding in a browser tool like this is for content preparation, not a substitute for a real security review.
  • Forgetting the apostrophe. Some hand-written escaping functions forget to encode ', leaving single-quoted HTML attributes vulnerable.
  • Assuming entities work everywhere. Named entities are an HTML-specific feature; plain-text emails, JSON payloads, and most non-HTML formats do not interpret them and will display them literally.

The Five Characters You Must Escape

HTML gives special meaning to a handful of characters, and encoding is simply the act of neutralising that meaning so text displays as text. The critical five are & (must become &amp; first, because every other entity starts with it), < (&lt;) and > (&gt;) which would otherwise open and close tags, and the quotes " (&quot;) and ' (&#39;) which can break out of attribute values. Encode those and a string like <script> shows up on the page as visible text rather than executing — which is precisely why encoding sits at the heart of preventing cross-site scripting (XSS).

The order matters: always escape the ampersand first. If you replace < with &lt; and only then escape ampersands, you would double-encode and turn your &lt; into &amp;lt;, which renders as the literal text "&lt;" instead of a "<" symbol. A correct encoder — like the one above — handles this sequencing for you, but knowing the rule explains the classic bug where user input shows up peppered with stray &amp; fragments after passing through two layers of naive escaping.

Context Is Everything: Element Text vs Attributes

A single escaping strategy is not enough, because the rules change with where the data lands. Text that sits between tags — inside a paragraph or a heading — mainly needs &, < and > handled. Text placed inside an attribute value additionally needs the relevant quote character escaped, or an attacker can close the attribute early and inject their own; that is why robust encoders escape both quote types. Data destined for a URL, a JavaScript string, or a CSS value needs entirely different encoding again — URL-encoding, JS string escaping, and so on.

The professional habit is "encode at the point of output, for the context you are outputting into." The same username might be HTML-entity-encoded when shown in a comment, URL-encoded when placed in a link, and JavaScript-escaped when injected into a script variable — three different transformations of one value. This tool covers the HTML side, which is by far the most common, but the underlying lesson carries everywhere: never trust that input is safe, and always match the escaping to the destination. That discipline is the difference between a site that resists injection and one that ships an XSS hole on its first user-generated field.

Related Free Tools From Arb Digital

For percent-encoding in links use the URL encoder decoder and build query strings with the query string builder. Turn HTML into Markdown with the HTML to Markdown converter or go the other way with Markdown to HTML, shrink markup with the HTML minifier, and browse the free online tools hub for more.

Frequently Asked Questions

What characters does HTML encoding convert?

Standard HTML escaping converts the five characters with special meaning in markup: ampersand, less-than, greater-than, double quote, and single quote, replacing each with its corresponding named or numeric entity.

Why is HTML encoding important for security?

HTML encoding is one of the defenses against cross-site scripting (XSS). When user-submitted text is inserted into an HTML element or attribute, encoding makes the browser display it as literal characters rather than run it as markup or script. It does not cover JavaScript, URL or CSS contexts, and it is not a substitute for a framework's own escaping.

What is the difference between named and numeric HTML entities?

Named entities like ampersand-amp-semicolon are readable shorthands for a limited set of common characters. Numeric entities reference any Unicode code point directly by number, so they can represent any character, including ones without a dedicated name.

Does HTML encoding protect JavaScript or URLs too?

No. HTML entity encoding is specific to HTML element content and attributes. JavaScript strings, URLs, and CSS values each require their own separate escaping methods to be safe in their respective context.

What happens if I encode already-encoded text?

You get double-encoding, where the ampersand in an existing entity gets re-escaped, turning something like ampersand-amp-semicolon into ampersand-amp-amp-semicolon, which then displays incorrectly.

Can this tool handle emoji and non-English text?

Accented letters and most non-Latin text, yes: with the encode all non-ASCII option on they become numeric entities. Emoji and other characters outside the Basic Multilingual Plane are encoded too, each as one numeric entity (for example &#128512;).

Which named entities can the decoder read?

Eleven: amp, lt, gt, quot, apos, nbsp, copy, reg, mdash, ndash and hellip. Every decimal or hexadecimal numeric entity is also decoded. Other named entities, such as eacute or euro, are left as typed.

This tool runs entirely in your browser using built-in JavaScript. Nothing you type or paste is uploaded, stored, or sent to any server.

Want this handled for you?

Need something more advanced? Try the free AI Website Audit and Keyword Research tools.