DoneInTab

HTML Entity Encoder & Decoder

Convert special characters to HTML entities and decode named or numeric references back to plain text. Supports standard named escapes (&, <), decimal (<), hex (<), and full Unicode/emojis.

Entity Format:
0 chars • 0 bytes
0 chars • 0 bytes
Context-Aware Escaping Note: HTML entity encoding prevents HTML markup injection into ordinary HTML body content. However, it does not make untrusted data safe in JavaScript blocks, CSS stylesheets, HTML event handlers (onclick), or URI query parameters. Always use context-specific escaping for attributes and script payloads.

Understanding HTML Entity Encoding

The 5 Core HTML Special Characters

HTML syntax reserves five specific characters for markup delimiters. Any occurrence of these characters in text should be converted to their corresponding entities:

CharNamed EntityNumeric DecNumeric Hex
&&&&
<&lt;&#60;&#x3C;
>&gt;&#62;&#x3E;
"&quot;&#34;&#x22;
'&#39; / &apos;&#39;&#x27;

Contextual Escaping Requirements

Security in web applications requires recognizing that different document contexts have distinct parsing rules:

  • HTML Body: Escaping &, <, > prevents injecting unauthorized tags.
  • HTML Attributes: Quotes (", ') must be escaped so an attacker cannot break out of quoted attribute boundaries.
  • JavaScript Blocks: HTML entities are NOT decoded inside <script> blocks. Use JSON serialization instead.
  • URLs & Links: URLs require percent-encoding (encodeURIComponent) to handle query delimiters like & and =.

Frequently Asked Questions

Why do HTML special characters need to be encoded?

In HTML syntax, characters like '<', '>', '&', '"', and '\'' serve as structural syntax markers for element tags, entities, and attributes. When inserting dynamic text into an HTML document without encoding, the browser's parser can mistake these characters for actual markup, causing rendering defects or cross-site scripting vulnerabilities.

What is the difference between standard named entities and numeric references?

Standard named entities use human-readable mnemonics such as &amp; for '&', &lt; for '<', &gt; for '>', and &quot; for '"'. Numeric character references refer directly to the Unicode code point of the character, either in decimal (e.g. &#60; for '<') or hexadecimal (e.g. &#x3C;). Numeric references work for any character in the entire Unicode standard, whereas named entities are limited to the standardized HTML5 entity dictionary.

Does HTML entity encoding guarantee security against all injection attacks?

No. HTML entity encoding is designed specifically for ordinary HTML body text context. It is not sufficient when user input is placed inside JavaScript script tags, CSS style rules, inline event handler attributes (such as onclick or onerror), or URL attributes. Different contexts require distinct escaping strategies (such as JSON serialization for scripts or URL percent-encoding for links).

Are my text snippets or code sent to any external server?

No. All encoding, entity replacement, and decoding occur strictly in memory within your browser via client-side JavaScript. No data is logged, transmitted, or stored on any server.

Does this decoder execute scripts or parse live HTML?

No. The decoding engine utilizes a pure string and code-point lookup approach rather than setting element.innerHTML or rendering live DOM nodes. Script tags, event attributes, or untrusted markup will be decoded as plain, inert text and never executed.

Related Developer Utilities