Encode text to HTML entities

Encode text as HTML character references so delimiters display as text.

freeworks offlinenothing uploaded
ToolHTML Entity Encode
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Characters that could be parsed as markup are replaced with named or numeric character references, selected for the surrounding text or attribute context. The HTML tokenizer resolves those references back to code points when parsing.

  • Named references improve readability while numeric references cover every code point.

Worked example

Script Tag
Escape HTML special characters to prevent XSS
Input
											<script>alert("xss")</script>
										
Output
												&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;
											

When to use this

Templates, CMS content, and code samples encode literal HTML delimiters.

Edge cases

  • An ampersand starting an existing entity can be double-encoded.
  • Quotes require attribute-context escaping.
  • Encoding text does not sanitize an unsafe URL scheme or script context.

References