HTML Entity Encoder/Decoder
Encode special characters to HTML entities or decode them back to text.
Plain Text
Encode →← Decode
HTML Entities
What are HTML Entities?
HTML entities are special sequences that represent characters which have meaning in HTML or can't be typed directly. They start with & and end with ;. For example, < represents < and & represents &. Essential for displaying code snippets, special symbols, and preventing XSS attacks.
Common HTML Entities
< → < (less than), > → > (greater than), & → & (ampersand), " → " (double quote), ' → ' (apostrophe), → non-breaking space, © → copyright, — → em dash, € → euro sign. Named entities are more readable; numeric entities (number;) work for any Unicode character.
When to Encode HTML Entities
When displaying user-generated content (prevents XSS attacks), when showing code examples in HTML, when using special characters in HTML attributes, when your text contains characters outside your document's encoding.
// JavaScript - Encode
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// JavaScript - Decode
function unescapeHtml(html) {
const div = document.createElement('div');
div.innerHTML = html;
return div.textContent;
}Frequently Asked Questions
- What's the difference between named and numeric entities?
- Named entities use words (© for ©), numeric entities use numbers (© or © for ©). Named entities are more readable but not available for all characters. Numeric entities work for any Unicode code point.
- Do I need to encode all special characters?
- At minimum, encode < > & and quotes inside attributes. Modern browsers handle most characters with UTF-8, but encoding is essential for characters that conflict with HTML syntax and for preventing XSS.
Related Tools
Base64 Encode/Decode
Encode text to Base64 or decode Base64 to text instantly.
URL Encode/DecodePercent-encode or decode URLs and query parameters.
JSON Formatter & ValidatorFormat, validate, and minify JSON with syntax highlighting.
Text Diff CheckerCompare two blocks of text and see the differences highlighted.