Encode & hash

HTML Escape

Convert text into HTML entities so it displays as characters instead of being parsed as markup.

Private by design — your data never leaves your device.
✓ Free forever✓ No sign-up✓ No ads✓ Works offline once loaded

HTML Escape

Convert text into HTML entities so it displays as characters instead of being parsed as markup.

Input

Plain text

Nothing is uploaded.

Output

Escaped HTML

Your result appears herePaste on the left and select “Escape HTML”

There are two reasons to escape HTML, and they arrive from opposite directions. Either you want to show markup on a page — a code sample, a tag name in documentation, an angle bracket in a comparison — and the browser keeps rendering it instead of displaying it. Or you are inserting text you did not write into a page, and you need to guarantee that a <script> in that text stays inert. Both are solved by the same operation: turn the characters that mean something to the HTML parser into entities that do not.

This tool escapes the minimal correct set by default — &, <, >, " and ' — which is precisely the set that can break out of text content or an attribute value. Nothing else is touched, so accented letters, CJK text and emoji pass through as themselves. An optional mode escapes every non-ASCII character as well, which some legacy pipelines still want. Encoding is done by the html-entities library at html5 level, in a Web Worker on your device.

How it works

How to use the html escape

  1. 1

    Paste the raw text

    A code snippet, a user comment, a product description, an error message that contains markup — anything you need to appear literally rather than be interpreted as HTML.

  2. 2

    Leave the minimal set selected unless you have a reason not to

    The default escapes only & < > " '. Turn on Escape all non-ASCII only if you are targeting a system that genuinely cannot handle UTF-8 — it makes the output substantially larger and no safer.

  3. 3

    Paste the result into your markup

    The escaped output is safe to drop into element content or into a quoted attribute value. The output panel reports how many entities were written, which is a quick sanity check that something was actually escaped.

Why the minimal set is the correct set

Five characters can change how an HTML parser reads a document. Escaping those five is a complete defence against HTML injection in text content and quoted attributes. Escaping more adds bytes, not safety.

  • &&amp;. Must go first, otherwise the ampersands introduced by the other replacements would themselves be escaped, producing &amp;lt; where you meant &lt;.
  • <&lt;. The character that starts a tag. On its own, escaping this prevents most injection.
  • >&gt;. Not strictly required in text content, but escaping it avoids accidentally closing a tag when content is concatenated, and costs nothing.
  • "&quot; and '&apos;. These matter inside attributes. An unescaped quote closes the attribute early, after which the attacker is writing attributes rather than data — which is how onerror= handlers get injected.

The apostrophe comes out as the named reference &apos;, because encoding runs at html5 level and HTML5 defines that name. One caveat worth knowing: &apos; was not defined in HTML 4, so if your output is destined for a genuinely ancient parser, substitute the numeric form &#39;, which every parser has always understood. In XML and HTML5 both forms are correct.

Because only these five change, the output stays readable. Café < 5 becomes Café &lt; 5 — the accent is untouched, which is what you want on any modern UTF-8 page.

Escaping every non-ASCII character: a legacy habit

The optional mode converts every character above ASCII into a named or numeric entity: café becomes caf&eacute;, an em dash becomes &mdash;, and CJK text becomes a long run of numeric references. It was standard practice in the 1990s, when a document's encoding was frequently unknown or wrong and entities were the only way to be certain a character survived.

That problem is gone. HTML5 defaults to UTF-8, every browser in use supports it, and a correct <meta charset="utf-8"> makes the whole exercise unnecessary. What remains is cost: output several times larger for non-Latin text, content that no longer matches when searched, and diffs that are unreadable.

There are still legitimate uses, and they are narrow: a downstream system that mangles UTF-8 and cannot be fixed, an email client with a hostile transfer encoding, or a template pipeline that transcodes to ASCII somewhere you do not control. If none of those apply — and they usually do not — leave the option off. Escaping é does not make a page safer; only the five special characters affect parsing.

Escaping is context-sensitive, and this covers one context

HTML escaping is the correct defence for text placed in element content or in a quoted attribute value. It is not sufficient everywhere, and knowing the boundary matters:

  • Inside a <script> block, HTML entities are not decoded. Injecting escaped text into JavaScript source does nothing to protect you — that context needs JSON encoding or JavaScript string escaping.
  • Inside a URL attribute such as href or src, escaping does not stop a javascript: scheme. Validate the scheme, and percent-encode the value.
  • Inside a style attribute or a CSS block, CSS has its own escaping rules; HTML entities do not apply.
  • Unquoted attributes can be broken out of with a space alone. Always quote your attributes; then escaping quotes is enough.

One more practical warning: escape once, at the point of output. Escaping on input and again on output gives you &amp;lt; rendering as a visible &lt;, the double-escaping bug that shows up in comment threads and support tickets everywhere. And in application code, prefer your template engine's automatic escaping over doing it by hand — this tool is for the cases where you are producing static markup, preparing a code sample, or debugging exactly what a system escaped.

Common questions

HTML Escape FAQ

Which characters does it escape by default?

Five: & becomes &amp;, < becomes &lt;, > becomes &gt;, " becomes &quot; and ' becomes &apos;. That is the complete set that can alter how an HTML parser reads text content or a quoted attribute value.

Should I turn on escape-all-non-ASCII?

Almost certainly not. It is a habit from before UTF-8 was universal. On a page declaring UTF-8, escaping accented and CJK characters only inflates the output and makes it harder to read or search. Use it only for a downstream system you know mangles UTF-8 and cannot be fixed.

Does escaping prevent XSS?

It prevents HTML injection in the contexts it covers: element content and quoted attribute values. It does not help inside script blocks, in URL attributes where a javascript: scheme is possible, or in CSS. Those contexts need their own encoding, and unquoted attributes are unsafe regardless.

Why is the apostrophe escaped as &apos; rather than &#39;?

Because escaping runs at html5 level, and HTML5 defines the &apos; name. It is also one of the five predefined XML entities, so the output is valid in both. Only HTML 4 lacked it — if you are targeting a parser that old, replace &apos; with the numeric &#39; after escaping.

My page shows &lt; instead of <. What went wrong?

The text was escaped twice — once on input and again on output, or by both your code and your template engine. Escape exactly once, at the point of rendering. Run the text through the HTML unescape tool to peel off the extra layer.