Skip to content

HTML Entity Encoder

Escape and unescape HTML entities to display markup safely.

Updated · Examples checked by automated tests

LOCAL WORKSPACENO UPLOAD REQUIRED

Escaped output

The converted value appears here.

Common entities

&&Ampersand
<&lt;Less than
>&gt;Greater than
"&quot;Double quote
 &nbsp;Non-breaking space
©&copy;Copyright
—&mdash;Em dash
€&euro;Euro sign

About HTML Entity Encoder

Any time user-supplied text is placed into an HTML document, characters that mean something to the parser have to be replaced with entity references - otherwise a stray angle bracket ends your paragraph and a quote breaks out of an attribute.

This encoder converts text to safe entities and decodes entity-laden markup back to readable text, which is equally useful for pasting code samples into a blog post.

How HTML Entity Encoder works in your browser

Basic mode escapes the five characters that matter for markup — &, <, >, " and apostrophe. Full mode additionally writes every non-ASCII character as a numeric entity. Decoding handles named entities as well as decimal and hexadecimal references.

Decoding reads entities as plain text rather than parsing them as live HTML, so decoded content cannot execute scripts in the page.

When to use it

  • Escaping a code sample so it displays correctly in a blog post.
  • Decoding entity-laden text copied from HTML source or an email.
  • Preparing text containing angle brackets for insertion into an attribute.

Worked examples

Show markup as text on a web page

Settings: Encode

Input

<a href="x">Tom & Jerry</a>

Expected output

&lt;a href=&quot;x&quot;&gt;Tom &amp; Jerry&lt;/a&gt;

The five characters with special meaning in HTML are escaped, so the browser displays the tag instead of creating a link.

Escape accented characters for an ASCII-only system

Settings: Encode, Escape all non-ASCII on

Input

Café ✓

Expected output

Caf&#233; &#10003;

Every character above code 127 becomes a numeric entity, so the text survives systems that mangle UTF-8. A modern page served as UTF-8 does not need this.

Limits and checks before you use the result

  • Escaping text for HTML content is not enough inside JavaScript, CSS or URL attributes, which have their own escaping rules.
  • Decoding uses your browser’s HTML parser, so it understands every named entity, but the result is only ever read as text.
  • This is not a sanitiser. Do not rely on it to make untrusted HTML safe to insert.

Frequently asked questions

Which characters are escaped?

In basic mode, the five characters that matter for markup safety: ampersand, less-than, greater-than, double quote and apostrophe. Full mode also escapes every non-ASCII character as a numeric entity.

Is escaping enough to prevent XSS?

HTML-escaping untrusted text before inserting it into markup prevents the most common injection, but attribute and script contexts need their own escaping rules.

Can it decode named entities?

Yes. Named entities, plus decimal and hexadecimal numeric references, are all decoded.

Related tools