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.
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:
| Char | Named Entity | Numeric Dec | Numeric Hex |
|---|---|---|---|
| & | & | & | & |
| < | < | < | < |
| > | > | > | > |
| " | " | " | " |
| ' | ' / ' | ' | ' |
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 & for '&', < for '<', > for '>', and " for '"'. Numeric character references refer directly to the Unicode code point of the character, either in decimal (e.g. < for '<') or hexadecimal (e.g. <). 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
Prettify, format, validate, and minify JSON data.
Encode and decode text or files to Base64.
Calculate SHA-256, SHA-384, SHA-512, and SHA-1 checksums.
Encode and decode URI query strings and paths.