FormatterHQ

HTML Escape

Convert the five HTML special characters into entities so text, code samples and user input show up literally on a web page instead of being treated as markup.

Loading tool…
Ready.

How to use the HTML Escape

  1. Type or paste into the Raw text box, or click Sample. You can also drop a text file on either box, or load one into the Escaped HTML box with its Open file button.
  2. The Escaped HTML box updates live as you type. It works both ways — edit the Escaped HTML side to convert back, or click ⇄ Swap to exchange the sides.
  3. Use Copy or Download on either box to take the result, or Clear to start again.

HTML escape: show markup as text

An HTML escape turns the characters that the browser treats as markup into character references. Once a string has been escaped, <b> is displayed as the four characters you typed rather than switching on bold text. This tool performs that HTML escape on any text you paste, instantly and entirely in your browser.

You need it whenever raw text ends up inside an HTML document: code samples in a blog post, error messages printed on a page, values echoed back from a form, or snippets pasted into a CMS that does not escape for you.

Which characters are escaped

Only five characters have a special meaning in HTML text and attribute values, so only these five are changed. Everything else — letters, digits, emoji, accented characters — is left exactly as it was.

CharacterBecomesWhy
&&amp;Starts every entity, so it must be escaped first
<&lt;Opens a tag
>&gt;Closes a tag; escaped for symmetry and safety
"&quot;Ends a double-quoted attribute value
'&#39;Ends a single-quoted attribute value

The single quote uses the numeric reference &#39; rather than &apos;, because &apos; was not defined in HTML 4 and some older parsers do not recognise it. The numeric form works everywhere.

Example

Input:

<a href="/search?q=tom&jerry" title='Tom's'>5 > 3</a>

Escaped output:

&lt;a href=&quot;/search?q=tom&amp;jerry&quot; title=&#39;Tom&#39;s&#39;&gt;5 &gt; 3&lt;/a&gt;

Paste the output into a page and the visitor sees the original anchor tag as text, including the ampersand in the query string.

HTML escaping and XSS

Cross-site scripting (XSS) happens when user-controlled text is inserted into a page without escaping, so a value like <script>…</script> runs as code. Escaping the five characters above neutralises this for the two most common places data lands: element content and quoted attribute values.

Escaping is context-specific, though. HTML escaping on its own does not make a value safe in these places:

  • Unquoted attributes such as <div class=VALUE> — a space is enough to start a new attribute. Always quote attributes.
  • URLs in href or src — a javascript: URL contains no special HTML characters at all. Validate the scheme instead.
  • Inside <script> or event handlers such as onclick — use JavaScript or JSON escaping for that context.
  • Inside <style> or inline CSS — use CSS escaping or, better, avoid putting untrusted data there.

In application code, rely on your template engine’s automatic escaping (Blade {{ }}, Twig, Jinja2, React JSX and Angular all escape by default) and use this tool for content you are writing by hand. For one-off tasks it is also handy for checking what a framework should be producing.

Escape vs. encode vs. unescape

This tool escapes the minimum set of characters and keeps non-ASCII text readable. If you need every accented letter or symbol converted to named entities such as &eacute; — for example for an email template or an old ISO-8859-1 page — use the HTML Encoder instead. To reverse the process and turn entities back into characters, use HTML Unescape. For XML documents, where the rules are slightly different, use XML Escape.

Common mistakes

  • Double escaping. Running escaped text through an escaper again produces &amp;lt;, which shows up on the page as &lt;. Escape once, at the moment you output the value.
  • Escaping on input. Store the original text in your database and escape when rendering. Escaped data is awkward to search, truncate or reuse in non-HTML outputs such as JSON or CSV.
  • Forgetting the ampersand. A hand-written replace that skips &, or handles it last, corrupts entities that already exist in the text. This tool handles all five characters in a single pass.

Privacy

The escaping runs locally with JavaScript. Your text is not uploaded, so you can safely escape snippets from private projects.

Frequently asked questions

Does HTML escaping prevent XSS completely?
It prevents XSS when the value is placed in element content or inside a quoted attribute. It does not protect unquoted attributes, javascript: URLs, inline scripts or CSS, which each need their own escaping or validation.
Why is the apostrophe converted to &#39; and not &apos;?
The named entity &apos; comes from XML and was only added to HTML in HTML5. The numeric reference &#39; is understood by every HTML parser and email client, so it is the safer choice.
Why are accented letters and emoji not escaped?
They have no special meaning in HTML, and a page served as UTF-8 displays them correctly. If you need them converted to entities anyway, use the HTML Encode tool with the “Encode every character” option.
Do I need to escape the > character?
Strictly, only < and & are required in element content. Escaping > as well is harmless, keeps output predictable and avoids problems in edge cases such as the ]]> sequence, so most libraries do it.
How do I undo HTML escaping?
Paste the escaped text into the Escaped HTML box — the Raw text box shows the decoded version — or open the HTML Unescape tool. It decodes these five entities plus every other named, decimal and hexadecimal reference defined in HTML5.

Last updated October 3, 2026

Guides

Related tools