Encode special characters and astral Unicode symbols into safe HTML entities and decode named, decimal, and hex entities in a single pass immune to double-decoding.
Related Tools
More in Security, Crypto & Encoding →URL Encode/Decode
Encode or decode URL components to handle special characters.
HTML Minifier
Minify HTML code.
Markdown to HTML
Convert Markdown syntax to raw HTML code with a live preview. Supports headers, lists, links, images, and code blocks.
Detect Unicode Char
Identify and analyze Unicode characters in your text. Detect invisible characters, emojis, and special symbols.
About HTML Entity Encoder & Decoder - Escape Special Characters
An HTML Entity Encoder is a developer tool that converts characters with special meaning in HTML (like <, >, &, ") into their corresponding HTML entities (like <, >, &, "). This process, known as escaping, is crucial for web security and data integrity. It prevents the browser from interpreting these characters as code, thereby protecting against Cross-Site Scripting (XSS) attacks. Conversely, the decoder converts these entities back into their original characters. This tool supports named entities (e.g., ©), decimal entities (©), and hexadecimal entities (©).
Input Formats
- Raw text with special characters
- HTML code snippets
- Strings with existing entities
Output Results
- Escaped HTML string
- Decoded plain text
- Copy-ready result
Key Features
Who is this for?
Web Security
Developers sanitizing user-generated content before rendering it to the DOM to prevent script injection.
Content Management
Writers escaping code snippets to display them literally in blog posts or documentation.
Data Migration
Cleaning up database entries that contain mixed encoded and unencoded content.
How to Use
Paste your text into the input area.
Select 'Encode' to escape special characters.
Select 'Decode' to revert entities to characters.
Copy the result.
Examples
Input
<script>alert('XSS');</script>Output
<script>alert('XSS');</script>Common Errors & Pitfalls
- Double encoding (e.g., &lt;)
- Forgetting to decode before editing
- Confusing URL encoding with HTML encoding
Code Examples
JavaScript
function encode(str) {
return str.replace(/[&<>'"/]/g, (char) => ({
'&': '&',
'<': '<',
'>': '>',
"'": ''',
'"': '"',
'/': '/'
})[char]);
}