HTML Entity Encoder
Escape and unescape HTML entities to display markup safely.
Updated · Examples checked by automated tests
Escaped output
The converted value appears here.
Common entities
| & | & | Ampersand |
| < | < | Less than |
| > | > | Greater than |
| " | " | Double quote |
| | Non-breaking space | |
| © | © | Copyright |
| — | — | Em dash |
| € | € | 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
<a href="x">Tom & Jerry</a>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é ✓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
Unix Timestamp Converter
Convert Unix timestamps to human dates and back, in UTC and local time.
Hash Generator
Generate SHA-1, SHA-256, SHA-384 and SHA-512 hashes from text or files.
SQL Formatter
Format SQL queries with consistent keyword casing and indentation.
XML Formatter
Pretty-print and validate XML documents with proper indentation.
YAML to JSON Converter
Convert YAML to JSON and back, with syntax checking.
JSON Formatter
Format, beautify and validate JSON with 2 or 4 space indentation.