Escape/unescape HTML entities

Escape ↔ unescape HTML entities

Runs locally in your browser with instant copy

Last updated: January 28, 2026
Frank Zhao - Creator
CreatorFrank Zhao

Escape html entities

Unescape html entities

Introduction / overview

This tool converts between two representations of the same text: raw characters (like <\texttt{<}) and HTML entities (like &lt;\texttt{\&lt;}). It helps you safely display text that might contain HTML, and it helps you decode entity-encoded content back to readable form.

Use Escape when you want to show text literally (for example in docs or previews). Use Unescape when you receive entity-encoded text (from logs, CMS exports, or API responses) and want to read or edit it.

Who is this for?

  • Developers previewing untrusted strings in HTML contexts.
  • Content editors fixing CMS text that contains entities like &amp;\texttt{\&amp;}.
  • Anyone copying code snippets into email/docs without accidentally turning tags into markup.

Related tools that pair well:URL Encoder/Decoder for safe transport of special characters in URLs, andText to Unicode when you need numeric character references.

How to use / quick start

  1. Pick the direction: Escape (top) or Unescape (bottom).
  2. Paste your text into the left input.
  3. The converted output appears instantly in the right box.
  4. Click the copy icon to copy the result.

What does it escape?

This tool focuses on the most common HTML-sensitive characters:\texttt{&}, <\texttt{<}, >\texttt{>},"\texttt{"}, and \texttt{\'}.

\texttt{&} \to \texttt{\&amp;}\\ \texttt{<} \to \texttt{\&lt;}\\ \texttt{>} \to \texttt{\&gt;}\\ \texttt{"} \to \texttt{\&quot;}\\ \texttt{\'} \to \texttt{\&\#39;}

Step-by-step examples

Example 1: escape a title tag

Suppose you want to show the literal text of an HTML tag in documentation.

Input\texttt{Input}==<title>IT Tool</title>\texttt{<title>IT\ Tool</title>}\Rightarrow&lt;title&gt;IT Tool&lt;/title&gt;\texttt{\&lt;title\&gt;IT\ Tool\&lt;/title\&gt;}

The output is safe to display inside HTML because the browser will render the characters instead of interpreting them as tags.

Example 2: unescape a snippet you received

If a CMS or API returns entity-encoded text, unescape it so you can read and edit it.

Input\texttt{Input}==Tom &amp; Jerry\texttt{Tom\ \&amp;\ Jerry}\RightarrowTom & Jerry\texttt{Tom\ \&\ Jerry}

After unescaping, the ampersand becomes a normal character again.

Real-world use cases

Safe preview of user input

You want to show a preview of a user-supplied string without it turning into real HTML.

Input: <b>Hi</b>\texttt{<b>Hi</b>}
Output: &lt;b&gt;Hi&lt;/b&gt;\texttt{\&lt;b\&gt;Hi\&lt;/b\&gt;}

Escape the input before rendering it in an HTML context.

Debugging encoded logs

Some logs or error messages include entities, especially when they pass through an HTML layer.

Input: Unexpected &quot;&gt;&quot;\texttt{Unexpected\ \&quot;\&gt;\&quot;}
Output: Unexpected ">"\texttt{Unexpected\ ">"}

Unescape to see the exact characters that caused the bug.

Copying snippets into docs

You are writing documentation where you need tags to appear as plain text.

Input: <li>Item</li>\texttt{<li>Item</li>}
Output: &lt;li&gt;Item&lt;/li&gt;\texttt{\&lt;li\&gt;Item\&lt;/li\&gt;}

Escape, then paste into your doc/knowledge base.

If you need to generate HTML from text, try Markdown to HTML after you finish preparing your content.

Cleaning CMS exports

Your CMS export contains entities and you need the raw text back for editing.

Input: R&amp;D &lt;2026&gt;\texttt{R\&amp;D\ \&lt;2026\&gt;}
Output: R&D <2026>\texttt{R\&D\ <2026>}

Unescape first, then if you will put it back into HTML, escape again at render time.

Common scenarios / when to use

Rendering untrusted text

Escape before rendering if the text might contain tags or HTML-looking characters.

Preparing docs snippets

Escape tags so they show up as text in a wiki, ticket, or markdown preview.

Investigating weird output

Unescape to see the actual characters that were hidden behind entities.

Comparing two versions

Escape both strings to compare safely in tools that render HTML.

Cleaning up exports

Unescape text copied from CMS exports, then re-escape at the final render step.

Quick sanity-check

Spot whether a string contains real tags or literal angle brackets.

When it might not be the right tool: if you need to decode a wide set of named entities (beyond the common ones) or handle full HTML parsing. This tool targets a practical subset for everyday work.

Tips & best practices

Escape at the boundary

A reliable habit is to escape right before you render untrusted text into HTML. That keeps your stored data clean and your rendering safe.

Avoid double-decoding

If you unescape &amp;lt;\texttt{\&amp;lt;} you should get&lt;\texttt{\&lt;}, not <\texttt{<}. That prevents surprising behavior when content is encoded multiple times.

Know what this tool covers

This tool covers a practical subset of entities. If your input contains many named entities, consider using a more specialized HTML entity library.

If you are preparing links, combine this with URL Encoder/Decoder to avoid breaking query strings.

Calculation method / formula explanation

Think of escaping as a deterministic replacement function. For a string ss, the escaped output is:

\mathrm{escape}(s) = s\;\text{with}\;\{\texttt{&},\texttt{<},\texttt{>},\texttt{"},\texttt{\'}\}\;\text{replaced by their entities}

Unescaping does the reverse replacement, but only for the specific entities this tool supports.

unescape(&amp;lt;)\mathrm{unescape}(\texttt{\&amp;lt;})==&lt;\texttt{\&lt;}\neq<\texttt{<}

Variables and mapping

  • ss: the input string.
  • escape(s)\mathrm{escape}(s): replaces characters with entities.
  • unescape(s)\mathrm{unescape}(s): reverses supported entities back to characters.

Related concepts / background info

What is an HTML entity?

An HTML entity is a text sequence that represents a character. For example,&lt;\texttt{\&lt;} is a way to represent<\texttt{<} inside HTML.

Escaping vs sanitizing

Escaping is about representation (show the text literally). Sanitizing is about removing or rewriting unsafe HTML. This tool escapes characters; it does not parse and sanitize HTML.

If you work with query strings, you may also want URL Encoder/Decoder because URL encoding and HTML entity escaping solve different problems.

Frequently asked questions (FAQs)

Does escaping make my app fully safe from XSS?

Escaping is a strong baseline for safely rendering text in HTML, but XSS prevention depends on context (HTML, attributes, URLs, scripts). Use context-aware escaping and your framework’s recommended patterns.

Why is \"\&lt;\" not turning into \"<\"?

Because it is double-encoded. One unescape step should produce &lt;\texttt{\&lt;}, not<\texttt{<}. This avoids decoding more than you intended.

Does this tool support every named HTML entity?

No. It focuses on the most common characters that frequently break markup.

What about numeric character references?

For numeric entities like &#65;\texttt{\&\#65;}, use Text to Unicode.

Should I escape before saving to the database?

Usually you store raw text and escape at render time. That keeps your data clean and avoids double-encoding.

What should I do if my input is a full HTML document?

If you need HTML parsing or sanitization, use a dedicated HTML parser/sanitizer. This tool is for string-level escaping/unescaping.

Limitations / disclaimers

This tool is designed for everyday developer workflows. It does not parse HTML, sanitize markup, or guarantee security in every execution context.

Not a substitute for security review

For security-sensitive use (XSS defense, sanitizing user-generated HTML), follow your framework and security team guidelines.

External references / sources

Escape/unescape HTML entities | CalculatorVast