ToolPane
Blog

HTML Entity Encoder/Decoder

Encode special characters to HTML entities or decode them back to text.

Plain Text
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 (&copy; for ©), numeric entities use numbers (&#169; or &#xA9; 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