HTML Escape / Unescape Tool

HTML escaping converts characters like <, >, and & into safe HTML entities. Browsers then display them as visible text instead of parsing them as markup. Developers run into HTML escaping and unescaping tasks constantly: rendering comments, embedding code snippets, or decoding scraped HTML. Skipping it, or using a mismatched tool, can break page layout or leave markup malformed.

This free html entity encoder and decoder runs entirely in your browser. There's no upload to a server, no signup, and no data leaving your device. Switch between escape and unescape instantly, choose named or numeric entity output, and get clean, correctly ordered results every time. Whether you're sanitizing a comment field or decoding an API response, this html escape tool gets it right on the first try.

Runs entirely in your browser
Named and numeric entity output
Copy and swap workflow built in

HTML Escape / Unescape Tool

Convert raw text into safe HTML entities or decode entities back into readable text.

Output format
Named entities
0 characters
0 bytes
Escape the five reserved HTML characters into safe entities.

What Is HTML Escaping (and Unescaping)?

HTML escaping replaces characters with special meaning in HTML with their matching entities. The main ones are <, >, &, ", and '. Raw < becomes &lt;, raw & becomes &amp;. This is also called html entity encoding, and the tool itself gets called an html entity encoder just as often. Without escaping, a stray < or & in user text can break page layout.

HTML unescaping reverses the process, turning entities back into their original characters. &lt; becomes <, &amp; becomes &. People also call this html entity decoding, the reverse job an html entity decoder performs. You'll typically unescape html entities when reading content pulled from an API, RSS feed, or CMS export. That covers anywhere text was encoded before you received it.

Some documentation writes this as HTML escape / unescape, treating both directions as one combined operation. Whether you call it HTML entity encoding and decoding or just escaping and unescaping, this tool covers both directions.

How HTML Escaping Works

HTML escaping works character by character, not byte by byte like binary encodings. Each reserved character maps directly to one HTML entity, either a named one like &amp; or a numeric one like &#38;. Named entities are easier to read; numeric ones work for any character, even ones without a defined name. The order of replacement matters, & must be escaped first, or later replacements double-encode it.

Here's a real walkthrough: escaping the string 5 < 10 & true. Each reserved character gets replaced in a single left-to-right pass, and everything else stays untouched.

Every reserved character becomes exactly one entity, there's no length inflation like Base64's 33% overhead. HTML escaping only touches five characters, so most text passes through unchanged. Rules for entity names come from the HTML5/WHATWG specification, which defines over 2,000 named entities in total.

Reserved character found
Position in string
HTML entity
<after `5 `&lt;
&after `10 `&amp;

Result:5 < 10 & true5 &lt; 10 &amp; true

How to Use This HTML Escape / Unescape Tool

Need to html escape online without installing anything? Whether you search escape html online or html escape characters online, the workflow here is the same. This tool is built for speed, no account, no install. A mode toggle switches between Escape and Unescape, and an entity-format toggle picks Named or Numeric output. Everything processes locally in your browser, so pasted text never touches a server.

Escaped output always reads as safe entities plus your original text. Decoding back to plain text, sometimes called html to text conversion, works the same way: paste, click Unescape, and copy. If the output looks unchanged, your input had no escapable characters to begin with.

  • Choose Escape to encode raw text, or Unescape to decode HTML entities back to text.
  • Paste your text or HTML snippet into the input box.
  • In Escape mode, pick Named entities like &amp; or Numeric entities like &#38;.
  • Click Escape HTML or Unescape HTML and the result appears instantly.
  • Use Copy Output to grab the result, or Swap Input/Output to reverse the operation.

Worked Examples

A single word does not show how HTML escaping and unescaping behave with real content. The table below walks through five common scenarios, from a plain sentence to a full HTML snippet. Every example uses UTF-8 input and named entities, this tool's default output format.

Notice the comparison-text example escapes both < and & in the same pass, in the correct order. Escaping & first prevents &lt; and &gt; from being mangled into &amp;lt; and &amp;gt;. That ordering detail is the most common source of double-escaping bugs.

Scenario
Input
Output
Plain sentence with an ampersand`Tom & Jerry``Tom &amp; Jerry`
HTML snippet`<div class="card">Hi</div>``&lt;div class=&quot;card&quot;&gt;Hi&lt;/div&gt;`
Attribute value with an apostrophe`Jenny's "Big" Sale``Jenny&#39;s &quot;Big&quot; Sale`
Comparison text`5 < 10 && 10 > 5``5 &lt; 10 &amp;&amp; 10 &gt; 5`
Unescape example`Tom &amp; Jerry&#39;s &quot;Big&quot; Sale``Tom & Jerry's "Big" Sale`

Common HTML Entities Reference

Only five characters need escaping in most HTML contexts, though a few more are useful to know. The table below covers the common set, every character this tool escapes by default, plus a few typographic extras. For the complete list of all 2,000+ named entities, see our full HTML Entities Reference.

Named entities like &copy; are easier to read in source code. Numeric entities like &#169; work even when a character has no defined name, which matters most for uncommon Unicode symbols.

A third form, hexadecimal, works the same way: &#x26; represents the same ampersand as &#38;. This tool's Numeric option outputs decimal by default, but Unescape mode decodes hex references automatically too.

Beyond the reserved five, HTML also defines named entities for accented letters and symbols, like &eacute; for e with acute and &ntilde; for n with tilde. These matter whenever you cannot guarantee UTF-8 encoding downstream, such as older email clients or legacy CMS exports.

Search engines see this list under different names too. Common variants include html escape quotes, html escape apostrophe, and html escape ampersand. For the two quote characters specifically, you'll also see html escape single quote and html escape double quote. For the angle brackets, that's html escape less than and html escape greater than. You'll also see this framed as escape character html, or the entities themselves called html escape codes, same table, different names.

Character
Name
Named entity
Numeric entity
Note
&Ampersand&amp;&#38;Must always be escaped first, or later replacements double-encode.
<Less-than sign&lt;&#60;Prevents the browser from reading text as the start of a tag.
>Greater-than sign&gt;&#62;Escaped by convention for symmetry, though less strictly required.
"Double quote&quot;&#34;Required inside a double-quoted HTML attribute value.
'Apostrophe&#39;&#39;&apos; is valid in HTML5 but &#39; works everywhere.
 Non-breaking space&nbsp;&#160;Common in pasted rich-text content.
©Copyright sign&copy;&#169;A typographic symbol, not a reserved character.
Em dash&mdash;&#8212;Frequently mangled by copy-paste from word processors.

Where HTML Escaping Doesn't Apply

HTML escaping only works where the browser is parsing HTML text content. Two common spots break that assumption: <script>/<style> elements, and HTML attributes that actually hold JavaScript or CSS.

Inside <script> and <style> tags, the browser doesn't parse entities at all, it treats the content as raw JavaScript or CSS. Escaping & inside a <script> block doesn't protect anything; it just prints a literal &amp; into your code, which is usually wrong. Dynamic values need proper JS or CSS string escaping instead, not HTML entities.

The same applies to attributes like onclick and style. <p onclick="NOT-HERE"> and <p style="NOT-HERE"> hold JavaScript and CSS respectively. HTML escaping alone doesn't make untrusted content safe inside them. Match the escaping to the actual context, not just to "it's inside an HTML tag."

Escaping HTML in Code: JavaScript, Python, and PHP

Most developers do not just need a one-off conversion; they need the same logic inside their own app. The snippets below cover three common languages for escaping and unescaping HTML. Each example escapes and unescapes the string Tom & Jerry, matching what this tool produces.

Javascript escape html and js escape html both point to the same problem: there's no single built-in string-escaping function. The DOM-based textContent approach above is the safest option for display. For server-side string escaping without a DOM, Node's escape-html npm package is a common lightweight choice. For escaping text inside a JavaScript string literal instead of HTML, use a JavaScript String Escape Tool.

Python html escape and php html escape are simpler, both ship a dedicated function in their standard library. No extra install is needed for either one.

JavaScript (browser)

// Escape (safe display)
const el = document.createElement("div");
el.textContent = "Tom & Jerry";
const escaped = el.innerHTML;
console.log(escaped); // Tom &amp; Jerry

// Unescape
const parser = new DOMParser();
const decoded = parser.parseFromString(escaped, "text/html").body.textContent;
console.log(decoded); // Tom & Jerry

Python

import html

escaped = html.escape("Tom & Jerry")
print(escaped)  # Tom &amp; Jerry

decoded = html.unescape(escaped)
print(decoded)  # Tom & Jerry

PHP

<?php
$escaped = htmlspecialchars("Tom & Jerry");
echo $escaped; // Tom &amp; Jerry

$decoded = htmlspecialchars_decode($escaped);
echo $decoded; // Tom & Jerry

Does HTML Escaping Prevent XSS? (Security & Privacy)

HTML escaping reduces XSS risk, but it isn't complete protection on its own. Escaping makes user text render as visible characters instead of markup, genuinely useful, and necessary. Full protection needs context-aware escaping: HTML body, attribute, JavaScript, and URL contexts each have their own rules.

On the privacy side, this tool runs entirely client-side in your browser. Pasted text and HTML never get uploaded to a server. Sensitive strings, draft comments, internal templates, API responses you're debugging, stay on your machine the entire time.

Treat this tool as a way to correctly escape or decode HTML entities for display, not a standalone security control. Sanitize any HTML you intentionally allow, rich text, Markdown output, with a dedicated sanitizer library. Validate untrusted input server-side too, not just at display time. For URL-context escaping, our URL Encoder/Decoder handles percent-encoding for query strings and paths.

Common HTML Escaping Errors and How to Fix Them

Most HTML escaping and unescaping problems come down to one of three issues. Recognizing the pattern saves you from re-checking your entire input.

If your text still looks double-escaped after one Unescape pass, run it through a second time. That usually means the original encoding happened more than once somewhere upstream.

Error
Cause
Fix
Text shows `&amp;lt;` instead of `<`Input was escaped twice, once by your code and again by a template engine's auto-escaping.Unescape once to remove a layer, then check whether it is still encoded.
Quotes break an HTML attribute" or ' inside an attribute value was not escaped to `&quot;` or `&#39;`.Escape quote characters before inserting text into any attribute.
& shows up literally instead of `&amp;`& was not escaped first, so it collided with entities from later replacements.Always escape & before <, >, ", and '.
Unescape leaves entities untouchedInput mixed named and numeric entities, or used hex references like `&#x26;`.Use a decoder that handles named, decimal, and hexadecimal entities.

HTML Escaping vs. Other Encodings

HTML escaping is not the only text-safety scheme, and picking the right one depends on where the output is headed. The table below compares HTML escaping against the encodings developers most often confuse it with.

Using the wrong encoding for the context leaves the underlying problem open. Html escape characters won't protect a URL, and percent-encoding won't protect HTML body text either. For query strings, our URL Encoder/Decoder handles percent-encoding correctly. For binary data like files and images, our Base64 Encoder/Decoder covers Base64 encoding and decoding. For string literals inside JavaScript, a JavaScript String Escape Tool applies the right escape sequences.

Encoding
Reserved Characters
Best For
HTML Escaping<, >, &, ", 'HTML body text and attribute values
URL EncodingReserved URL characters (%XX sequences)Query strings, paths, form data
JavaScript String Escaping\n, \", \\, unicode escapesText embedded inside a JS string literal
Base64 EncodingFull binary → 64-char alphabetBinary data inside text-only systems (APIs, emails, data URIs)

Frequently Asked Questions

Frequently Asked Questions