HTML Entity Encoder & Decoder

Encode text to HTML entities or decode them back. Named, decimal and hex output, four encoding levels, XSS warnings. Free and runs in your browser.

Advertisement

HTML Entity Encoder and Decoder

This HTML entity encoder converts text into HTML entities and converts entities back into plain text, in one place, instantly. Paste a snippet containing <, >, & or quotes and get output that a browser will display as literal characters instead of parsing as markup. Choose named entities, decimal numeric references, hexadecimal references or a mixed strategy, and choose how aggressive the encoding should be. Everything runs in your browser — nothing is uploaded.

The two jobs it does are exact inverses. Encoding takes <div>Hello</div> and yields &lt;div&gt;Hello&lt;/div&gt;, which renders on the page as the tag text rather than creating an element. Decoding takes entity-laden text out of a log line, an XML export or a database column and gives you back the original characters.

Why HTML Entity Encoding Matters

HTML has exactly five characters that carry structural meaning. If untrusted input containing them is written into a page unescaped, the browser cannot tell your markup from the attacker's — that is cross-site scripting in one sentence. Entity encoding removes the ambiguity by replacing each dangerous character with a token that means “display this glyph” rather than “begin a tag”.

The five that always need encoding in an HTML context:

  • &&amp; (decimal &#38;, hex &#x26;) — encode this one first, or you will double-encode everything that follows
  • <&lt; (&#60;, &#x3C;)
  • >&gt; (&#62;, &#x3E;)
  • "&quot; (&#34;, &#x22;) — essential inside double-quoted attributes
  • '&apos; (&#39;, &#x27;) — essential inside single-quoted attributes

Beyond those, a useful reference set of named entities: &nbsp; for a non-breaking space, &copy; ©, &reg; ®, &trade; ™, &euro; €, &pound; £, &yen; ¥, &cent; ¢, &deg; °, &plusmn; ±, &times; ×, &divide; ÷, &frac12; ½, &frac14; ¼, &frac34; ¾, &mdash; —, &ndash; –, &hellip; …, &bull; •, &sect; §, &para; ¶, &dagger; †, &prime; ′, &larr; ←, &rarr; →, &uarr; ↑, &darr; ↓.

Named, Decimal and Hexadecimal Entities

Every character can be written three ways, and the tool lets you pick which:

  • Named&amp;, &copy;. Readable, but only defined for characters that have a name.
  • Decimal&#38;. A numeric character reference using the code point in base 10. Works for every Unicode character.
  • Hexadecimal&#x26;. The same thing in base 16, which is how code points are conventionally written.
  • Mixed — the default: a named entity when one exists, decimal otherwise. This gives readable output without leaving exotic characters unencoded.

All three forms are equivalent to the parser. Numeric references are the safer default when output is consumed by something other than a full HTML parser, because named entities beyond the core five are not universally recognised in XML.

Four Encoding Levels

Encoding more than necessary bloats output and makes diffs unreadable; encoding less than necessary is a vulnerability. The tool offers four levels so you can match the context:

  • Minimal — only the five structural characters. The right default for HTML body and attribute output; it leaves accented letters and emoji intact, which is what you want on a UTF-8 page.
  • Standard — the five, plus control characters and everything outside printable ASCII (code points below 32 or above 126). Use when the output must survive a legacy pipeline that mangles non-ASCII bytes.
  • Extended — the five, plus all non-ASCII characters (above code point 127), leaving printable ASCII punctuation alone.
  • Aggressive — every single character becomes an entity, including letters and spaces. Genuinely useful only for obfuscation demonstrations and for testing whether a parser normalises entities before applying a filter.

Encoding as XSS Defence — and Its Limits

Entity encoding is contextual output encoding, and the context decides whether it works. Inside an HTML element or a quoted attribute value, it is correct and sufficient. Elsewhere it is not:

  • Inside <script> — the HTML parser does not decode entities in a script data block, so entity encoding neither protects you nor round-trips. Serialise to JSON instead.
  • Inside a URL attribute&#106;avascript: decodes to javascript:, so an entity-encoded payload in href still executes. Validate the scheme, and use percent-encoding via the URL encoder for the query string.
  • Unquoted attributes — encoding quotes does nothing when there are no quotes to break out of; a space is enough to inject a new attribute. Always quote.
  • Inside CSS or an event handler — different escaping rules apply entirely.

The tool flags patterns in your input that suggest an XSS attempt — on* event handler attributes, script and other dangerous tags such as iframe, object, embed and frame, and text that is already heavily entity-encoded (a classic evasion signal). Treat these as review prompts, not as a verdict. And encode on output, never on input: storing pre-encoded data guarantees double-encoding somewhere downstream, which is how &amp;amp; ends up in your page titles. Pair this with a strong Content Security Policy so that a missed escape does not become an executed script.

How to Use the HTML Entity Encoder

  1. Choose Encode or Decode.
  2. Paste your text or markup into the input box.
  3. Pick an entity format — mixed, named, decimal or hex.
  4. Pick an encoding level — minimal for normal web output, higher when a downstream system demands it.
  5. Read the output and the statistics panel, which counts total entities produced and breaks them down by named, decimal and hex.
  6. Review any security warnings, then copy the result.

Decoding accepts all three forms in the same input, so mixed text such as &lt;p&gt;caf&#233; &#x26; bar&lt;/p&gt; comes back intact.

Frequently Asked Questions

What is HTML entity encoding?

It is the replacement of characters that have structural meaning in HTML — or that are hard to type — with escape sequences the browser renders as the literal glyph. < becomes &lt;, so the browser displays a less-than sign instead of starting a tag.

Is this HTML encoder free?

Yes. Free, no account, no length limit, and it runs entirely in your browser.

Which characters must I encode?

At minimum &, <, >, " and '. Encode the ampersand first so you do not re-encode the entities you have just created.

What is the difference between named and numeric entities?

Named entities like &copy; are readable but exist only for a defined list of characters. Numeric references — decimal &#169; or hex &#xA9; — work for any Unicode code point. Browsers treat all three identically.

Does entity encoding stop XSS?

In HTML element and quoted-attribute contexts, yes. It does not protect JavaScript contexts, URL attributes such as href and src, CSS, or unquoted attributes — each needs its own escaping rules.

Should I encode data before storing it in my database?

No. Store the raw value and encode at the point of output, using the encoding appropriate to that context. Encoding on input causes double-encoding and breaks searching, sorting and reuse in non-HTML contexts.

Why do I see &amp;amp; in my output?

That is double encoding: an already-encoded string was encoded again. Decode it here until it stops changing, then fix the pipeline so encoding happens exactly once, at output.

Do I need to encode accented characters and emoji?

Not on a UTF-8 page — they display correctly as-is, so minimal encoding is the right choice. Use extended or standard level only when output passes through a system that cannot handle non-ASCII bytes.

Can it decode all three entity formats at once?

Yes. The decoder handles named entities, decimal references and hexadecimal references in the same input, in any combination.

Is my input sent to a server?

No. Encoding, decoding and the security checks all run locally in your browser. Nothing is transmitted or stored.

What Is HTML Encoding

HTML encoding (also called HTML entity encoding) converts special characters into their HTML entity equivalents so they display correctly in web pages rather than being interpreted as HTML markup. Characters like <, >, &, ", and ' have special meaning in HTML—they define tags, attributes, and entities. When these characters appear in user content, they must be encoded to prevent rendering issues and security vulnerabilities.

HTML encoding is one of the most important defenses against Cross-Site Scripting (XSS), the most prevalent web security vulnerability. When user input is inserted into a web page without encoding, an attacker can inject malicious HTML or JavaScript that executes in other users' browsers. Proper encoding neutralizes these attacks by ensuring special characters are treated as text, not code.

How HTML Encoding Works

HTML encoding replaces special characters with named or numeric entity references:

CharacterNamed EntityNumeric EntityContext
<<<Opening tag delimiter
>>>Closing tag delimiter
&&&Entity start character
"""Attribute value delimiter
'''Attribute value delimiter
///Tag closing character
Space (non-breaking)  Preserved whitespace

Encoding contexts matter: Different insertion points in HTML require different encoding strategies:

  • HTML body: Encode <, >, &, ", '
  • HTML attributes: Encode all non-alphanumeric characters as entities
  • JavaScript context: Use JavaScript string escaping, not HTML encoding
  • URL context: Use URL/percent encoding, not HTML encoding
  • CSS context: Use CSS escaping

Using the wrong encoding for the context is a common source of XSS vulnerabilities.

Common Use Cases

  • XSS prevention: Encode user-supplied data before inserting it into HTML to prevent script injection
  • Content display: Ensure code snippets, math formulas, and special characters render correctly on web pages
  • Email templates: Encode special characters in HTML emails to prevent rendering issues across email clients
  • CMS content: Safely display user-generated content (comments, forum posts, profiles) without allowing HTML injection
  • API responses: Encode HTML entities in JSON responses that will be rendered in the browser

Best Practices

  1. Encode on output, not input — Store raw data and encode when rendering; this preserves data integrity and allows context-appropriate encoding
  2. Use context-appropriate encoding — HTML body encoding is different from attribute encoding, JavaScript encoding, and URL encoding
  3. Use framework auto-encoding — Modern frameworks (React, Angular, Vue) auto-encode by default; don't disable this protection
  4. Never rely on blocklist filtering — Trying to strip dangerous tags is fragile; encoding is the correct defense
  5. Double-check dangerouslySetInnerHTML / v-html — When frameworks require raw HTML insertion, sanitize with a library like DOMPurify first

Frequently Asked Questions

What are HTML entities and why are they important?+

HTML entities encode special characters that have meaning in HTML: < becomes &lt;, > becomes &gt;, & becomes &amp;, " becomes &quot;, ' becomes &#39; or &apos;. Why important: prevents breaking HTML structure, avoids XSS (cross-site scripting) attacks, displays reserved characters literally, ensures proper rendering. Example: displaying code <script> without executing it. Two formats: named entities (&nbsp;), numeric entities (&#160; decimal, &#xA0; hex). Always encode user input before displaying in HTML to prevent security vulnerabilities.

How does HTML encoding prevent XSS attacks?+

XSS (Cross-Site Scripting) injects malicious scripts into pages. Without encoding: user input <script>alert("XSS")</script> executes as code. With encoding: &lt;script&gt;alert("XSS")&lt;/script&gt; displays as text. Attack vectors: form inputs, URL parameters, cookies, database content. Defense layers: (1) Encode output (HTML entities), (2) Validate input (whitelist), (3) Content Security Policy headers, (4) HttpOnly cookies. Encoding alone not sufficient: use comprehensive XSS prevention, sanitize HTML if allowing markup, use frameworks that auto-encode (React, Vue). This tool helps encode untrusted content before rendering.

What is the difference between HTML encoding and URL encoding?+

HTML encoding: for HTML content, encodes <>&"' to entities, used in HTML body/attributes, prevents HTML interpretation. URL encoding (percent encoding): for URLs, encodes space as %20 or +, special chars as %XX hex, used in query strings/paths, prevents URL parsing issues. Different contexts need different encoding: HTML entity: &lt; for <, URL encoding: %3C for <. Don't mix: URL-encoded in HTML looks wrong (%20 displays as %20). When to use: HTML encoding in page content, URL encoding in hrefs/src attributes, both in JavaScript strings. This tool does HTML entity encoding; use separate tool for URL encoding.

Which characters must be encoded in HTML attributes?+

Required in attribute values: double quote becomes " if using double-quoted attributes, single quote becomes ' if using single-quoted attributes, < becomes < (less common but safe), & becomes & (always). Example:

. Attribute context matters: URL attributes (href, src) also URL-encode, JavaScript attributes (such as event handlers) use JSON.stringify, data attributes use HTML encode, style attributes use CSS encode. Best practice: always use quotes around attributes, use double quotes with " encoding, encode & in all attributes. This tool encodes for safe attribute insertion.

How do I handle international characters and Unicode in HTML?+

Unicode characters can be: (1) Used directly if UTF-8 charset: <meta charset="UTF-8">, no encoding needed. (2) HTML entities: &eacute; for é (named), &#233; for é (decimal), &#xE9; for é (hex). Modern approach: use UTF-8 directly, it's simpler and more readable. Encode entities only for: HTML special chars (<>&"), control characters, invisible chars, compatibility with non-UTF-8 systems. Emoji: use directly in UTF-8 or numeric entities &#128512; 😀. Right-to-left text: use proper HTML markup (dir="rtl"), not entities. This tool preserves Unicode by default, encodes only HTML special characters.

What is the difference between encoding and sanitizing HTML?+

Encoding: converts special chars to entities, displays everything as text, no HTML tags work, safest for untrusted content, example: <b>&lt;b&gt;. Sanitizing: allows some HTML, removes dangerous tags/attributes, permits formatting (<b>, <i>, <p>), blocks scripts (<script>, onclick), more complex. Use encoding when: displaying plain text, user input shown as-is, no formatting needed, maximum security. Use sanitizing when: allowing rich text editors, blog comments with formatting, markdown converted to HTML. Libraries: DOMPurify, sanitize-html for sanitizing. Never trust user HTML: always sanitize or encode. This tool does encoding (safest); use sanitizing libraries for rich text.

How do I encode HTML in JavaScript and other programming languages?+

JavaScript: no built-in HTML encode. Manual: text.replace(/</g, "&lt;").replace(/>/g, "&gt;"). Libraries: DOMPurify, he, lodash escape. DOM method: textContent auto-encodes (safe), innerHTML doesn't (unsafe). Python: html.escape(text) built-in, or markupsafe.escape(). PHP: htmlspecialchars($text) or htmlentities($text). Java: StringEscapeUtils.escapeHtml4() (Apache Commons). Ruby: ERB::Util.html_escape() or CGI.escapeHTML(). C#: HttpUtility.HtmlEncode() or WebUtility.HtmlEncode(). Server-side encoding preferred: do before sending to browser. This tool for quick manual encoding and testing; use language built-ins in production code.

What are common mistakes when encoding HTML?+

Double encoding: encoding already-encoded text, &lt; becomes &amp;lt;, displays as &lt; not <. Fix: decode first, then encode. Wrong context: HTML encoding in JavaScript strings, needs JSON escaping too. Incomplete encoding: missing quotes or ampersands, still vulnerable. Over-encoding: encoding Unicode unnecessarily, makes text unreadable. Not encoding: forgetting to encode user input, XSS vulnerability. Encoding at wrong time: too early (breaks processing), too late (already executed). Inconsistent encoding: some fields encoded, others not. Testing: verify with XSS payloads: &lt;script&gt;alert(1)&lt;/script&gt;, " onclick="...". This tool helps test encoding correctness before deploying.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.