Interested in sponsoring? Reach out to discuss placements.
HTML Entity Encoder & Decoder
Encode and decode HTML entities.
Last updated: June 2026
Example
- In:
- <div class="title">Tom & Jerry</div>
- Out:
- <div class="title">Tom & Jerry</div>
Guide
Introduction
HTML treats <, >, &, and quote characters as syntax — not literal text. Displaying user-supplied content like <script>alert(1)</script> or Tom & Jerry in a web page without escaping invites cross-site scripting (XSS) and broken markup. Template engines, React's JSX, and modern frameworks escape by default, but CMS exports, email HTML fragments, legacy PHP templates, and API responses still arrive with raw or double-encoded entities that need inspection. When debugging "why does this ampersand render wrong" or preparing safe HTML snippets for documentation, you need encode and decode utilities that do not exfiltrate your content to unknown servers.
Certoflow's HTML Entity Encoder and Decoder transforms between plain text and HTML entity representations entirely in your browser. Toggle encode mode to escape dangerous characters; toggle decode mode to reverse <, >, &, ", and ' back to readable text. Processing is local — customer names, support ticket bodies, and unreleased marketing copy stay on your device. Light and dark theme support keeps template debugging comfortable during long review sessions.
What this tool does
Dual-mode conversion with shared input/output workflow:
| Mode | Input | Output |
|---|---|---|
| Encode | Plain text or HTML | Entity-escaped safe text |
| Decode | Entity-encoded text | Plain text or HTML |
Encoded characters:
| Character | Entity |
|---|---|
& | & |
< | < |
> | > |
" | " |
' | ' |
Additional features include example loading, paste from clipboard, copy output, and clear fields — standard Certoflow toolbar actions.
How it works
Encoding replaces five critical characters using a deterministic map:
const ENTITY_MAP = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
};
function encodeHtmlEntities(text) {
return text.replace(/[&<>"']/g, (char) => ENTITY_MAP[char]);
}
Ampersand is encoded first in the replacement chain conceptually — the regex handles each occurrence independently, producing correct output for strings like Tom & Jerry → Tom & Jerry.
Decoding leverages the browser's HTML parser via a temporary textarea element:
function decodeHtmlEntities(text) {
const textarea = document.createElement("textarea");
textarea.innerHTML = text;
return textarea.value;
}
This approach resolves named entities (&, <) and numeric entities (<, <) that the browser recognizes — broader than the five-character encode set. Processing never leaves your browser.
Example encode:
| Input | Output |
|---|---|
<div class="title">Tom & Jerry</div> | <div class="title">Tom & Jerry</div> |
Real-world examples
XSS prevention preview
Before inserting user comment "Great <script>..." into a template, encode locally to verify the escaped output shows literal angle brackets in HTML source rather than executable script tags. Entity encoding is one layer — always combine with Content Security Policy, framework auto-escaping, and input validation in production.
CMS content migration
Exporting WordPress or Drupal HTML sometimes double-encodes entities (&amp;). Decode once locally, inspect plain text, re-encode cleanly, and compare with HTML Formatter for structural review of surrounding markup.
Email template debugging
Marketing emails mix HTML and plain-text fallbacks. Encode special characters in dynamic insertion points ({{userName}} adjacent to ampersands) to preview how MIME HTML parts render. Format CSS inline styles with CSS Formatter separately.
JSON API string preparation
JSON payloads embedding HTML snippets need escaped quotes inside string values. Encode HTML first, then wrap in JSON using JSON Formatter to verify valid string escaping at both HTML and JSON layers.
URL parameter cross-check
HTML entity encoding differs from URL percent-encoding. After HTML encoding, compare URL-specific characters with URL Encoder and URL Decoder when parameters traverse both HTML forms and query strings.
Common mistakes
Treating entity encoding as complete XSS defense. Encoding < prevents script injection in HTML text nodes but not in all contexts (JavaScript event attributes, CSS url(), JSON embedded in script tags). Use context-appropriate escaping and CSP headers.
Double-encoding. Encoding already-safe text turns & into &, then re-encoding produces &amp;. Decode first if uncertain about encoding state.
Decoding untrusted HTML before sanitization. Decoding <script> tags restores executable markup in DOM contexts. Decode for inspection in Certoflow's text areas — do not inject decoded output into innerHTML without sanitization.
Confusing HTML entities with XML/CDATA. XML has different escaping rules. HTML5 entity decoding via browser parser handles common cases but may differ from strict XML parsers.
Expecting encode to handle all Unicode characters. Certoflow encodes five syntax-critical ASCII characters. Arbitrary Unicode (emoji, CJK) may remain unencoded — usually correct for UTF-8 pages. Use numeric entities manually when ASCII-only transport requires it.
Using decode output in production templates without review. Decoded content may contain markup. Treat as untrusted until sanitized.
Mixing with Base64 encoding. Base64 encodes bytes for transport; HTML entities encode characters for markup safety. Use Base64 Encode for binary data, entity encoding for HTML text.
Use cases
Frontend developers verifying escape behavior before integrating user-generated content displays.
Backend engineers preparing safe HTML fragments for email and notification templates.
Content editors debugging entity display issues in CMS exports without server-side tools.
Security reviewers demonstrating XSS mitigation through escaped versus raw payload comparison.
Technical writers producing accurate entity examples in HTML documentation.
Related tools
Structure HTML with HTML Formatter. Style review uses CSS Formatter. URL contexts need URL Encoder. Transport encoding differs with Base64 Encode. JSON payloads benefit from JSON Formatter.
FAQ
Is my text sent to a server?
No. Encoding and decoding run entirely in your browser.
Which characters are encoded?
Ampersand, less-than, greater-than, double quote, and single quote.
Does decode support numeric entities?
Yes. Browser HTML parsing resolves &#...; and &#x...; forms in addition to named entities.
Is this sufficient for XSS prevention?
Entity encoding is one layer. Always use framework escaping, input validation, and Content Security Policy in production applications.
Can I encode entire HTML documents?
Yes, but encoding < and > converts tags to visible text — useful for displaying code examples, not for preserving document structure.
Can I use this offline?
Yes, after page load.
Why does decode use a textarea element?
The browser's HTML parser resolves entities correctly — a reliable cross-browser approach without importing heavy libraries.
Encode or URL encode for form fields?
HTML forms submitting to servers typically need URL encoding for query parameters (URL Encoder), not HTML entity encoding. Entity encoding targets HTML document content insertion.
Does dark mode affect encoding?
No. Theme is display-only.
Can I round-trip encode and decode?
Yes. Encode plain text, copy output, switch to decode mode, paste — original text restores for the five-character encode set.
Frequently Asked Questions
- Which characters are encoded?
- Ampersand, less-than, greater-than, double quote, and single quote.
- Is this sufficient for XSS prevention?
- Entity encoding is one layer. Always use framework escaping and Content Security Policy in production apps.
People also use
Related tools that complement this workflow.
HTML Formatter
Indent and format HTML markup.
Developer ToolsURL Encoder
Encode text for URL query parameters.
Developer ToolsBase64 Encode
Encode text to Base64 with UTF-8 support.
Developer ToolsJSON Formatter & Validator
Format and validate JSON with one click.
Developer ToolsCSS Formatter
Format and indent CSS stylesheets.
Interested in sponsoring? Reach out to discuss placements.