HTML entities encoder

Encode and decode HTML entities

HTML Entities Encoder

Encode or decode HTML special characters

Encode HTML
Swap
&&
<&lt;
>&gt;
"&quot;
'&#39;
/&#x2F;

SQL injection and XSS: how they work and how to stop them

TL;DR

What is HTML entities encoder?

HTML entity encoding replaces characters that have special meaning in HTML with their entity equivalents: < becomes &lt;, > becomes &gt;, & becomes &amp;, and " becomes &quot;. This prevents browsers from interpreting the characters as HTML markup.

Common use cases

  • XSS prevention: encode user-supplied text before inserting it into HTML to prevent script injection
  • Template debugging: encode HTML snippets to display source code in a web page without it being parsed
  • Special characters: display typographic characters (copyright ©, trademark ™, arrows) using named entities
  • Email templates: some email clients require HTML-encoded characters for reliable rendering

Frequently asked questions

When do I need to encode HTML entities?

Any time you insert untrusted text (user input, database content, API responses) into an HTML document, encode it first. The critical characters are <, >, &, ", and '. Modern templating engines (React JSX, Vue templates, Jinja2) escape these automatically, but raw string concatenation into HTML does not.

What is the difference between named and numeric entities?

Named entities use a word: &lt; for <, &copy; for ©. Numeric entities use the Unicode code point in decimal (&60;) or hex (&#x3C;). Named entities are more readable; numeric entities work for any character, including those with no named form.

See also

  • URL encoder: URL encoding is the complementary operation for encoding special characters in query strings and path segments
  • Markdown preview: preview Markdown that contains HTML entities to confirm they render correctly in the final output