Xerobit

Escape Character HTML: Encode and Decode Entities

Use this escape character HTML tool to encode the characters HTML treats as markup (& < > " '), or switch to Unescape to turn named and numeric entities back into plain characters. It runs in your browser, so the text never leaves your device.

Only applies when escaping.

Converts " to &quot; and ' to &#39;. Turn off for text between tags.

Result

&lt;a href=&quot;/search?q=salt&amp;pepper&quot;&gt;Tom&#39;s café&lt;/a&gt;

8 characters escaped.

How to use the html escape

  1. Paste the text or code into the box. The default example already contains every special character.
  2. Pick Escape to encode, or Unescape to decode entities back into plain text.
  3. When escaping, choose how to treat non-ASCII characters: keep them, or write them as decimal, hex or named entities.
  4. Leave Escape quotes on for attribute values, or turn it off for plain text between tags, then copy the result.

What is an escape character in HTML?

HTML has no backslash escape. The escape character HTML uses is the ampersand: an entity starts with & and ends with ;, and the browser replaces it with the character it names. That is how you show a literal < in a page without the parser reading it as the start of a tag.

Five characters need escaping in most contexts. The ampersand starts entities, the less-than sign starts tags, the greater-than sign closes them, and the two quote characters end attribute values. Everything else can normally be written as it is when the page is served as UTF-8. In short, write the entity instead of the raw symbol.

HTML escape codes for the special characters

These html escape codes cover almost all everyday escaping. The same table applies when you escape characters html pages use in text nodes and in attribute values.

CharacterEntityNumericWhy escape it
&&amp;&#38;Starts every entity
<&lt;&#60;Starts a tag
>&gt;&#62;Closes a tag
"&quot;&#34;Ends a double-quoted attribute
'&#39;&#39;Ends a single-quoted attribute

The apostrophe has a named form, &apos;, but it was not part of HTML 4 and old parsers ignore it, so this tool writes &#39;. Python's html.escape writes &#x27; for the same character: both decode to the same apostrophe.

Escape or unescape non-ASCII text

If a page is served as UTF-8, accented letters and symbols can stay as they are. Entities for non-ASCII text matter when the file passes through a system that mangles encodings, or when you want the source to survive in plain ASCII, such as an email template or a legacy CMS field.

The three output styles encode the same code point three ways. For the euro sign (U+20AC): decimal &#8364;, hex &#x20AC; and named &euro;. Characters above U+FFFF, such as emoji, are written as one reference for the whole code point, for example &#128512;, not as two surrogate halves. In named mode, any character without an HTML 4 name falls back to a decimal entity.

Decoding: named, decimal and hex references

Unescape mode understands the 252 named entities of HTML 4 plus &apos;, decimal references like &#169; and hex references like &#xA9;. Names are case-sensitive: &Eacute; is a capital E with acute, &eacute; the lowercase one.

  • Unknown names such as &foo; are left untouched.
  • Reference &#0;, values above U+10FFFF and surrogate halves decode to the replacement character U+FFFD.
  • References 128 to 159 follow the Windows-1252 table the way browsers do, so &#128; becomes the euro sign.

JavaScript escape HTML: doing it in code

To escape html javascript strings before inserting them with innerHTML, replace & first and the rest after, otherwise the ampersands you just added get escaped twice: s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"). A safer habit is to assign to textContent, which never parses markup at all.

Escaping is context specific. The table above is right for text and quoted attributes. It is not enough inside a <script> block, inside a URL (use the URL encoder) or inside a CSS value. For JSON or JavaScript string literals use the string escape tool instead.

Common mistakes with HTML escaping

Using a backslash as the escape character HTML expects does nothing in markup, because the parser ignores it.

Double escaping is the usual bug: text that goes through the escaper twice turns &amp; into &amp;amp; and shows literal entity text on the page. Escape once, at output time, and keep stored data raw.

The other mistake is skipping the ampersand because a string "has no entities". A URL like ?a=1&copy=2 contains &copy, which some browsers decode as the copyright sign even without a semicolon. Escaping every ampersand avoids that. For a broader encode and decode comparison see the HTML encoder and decoder.

Worked examples

ExampleInputResult
Escape an anchor tagText: <a href="/search?q=salt&pepper">Tom's</a>; Mode: escape; Non-ASCII characters: keep; Escape quotes: yes&lt;a href=&quot;/search?q=salt&amp;pepper&quot;&gt;Tom&#39;s&lt;/a&gt;
Non-ASCII as named entitiesText: Café © 2026, price €5; Mode: escape; Non-ASCII characters: named; Escape quotes: yesCaf&eacute; &copy; 2026, price &euro;5
Decode entitiesText: &lt;p&gt;Caf&eacute; &amp; cr&egrave;me &#8364;5 &#x1F600;&lt;/p&gt;; Mode: unescape; Non-ASCII characters: keep; Escape quotes: yes<p>Café & crème €5 😀</p>
Text between tags (quotes kept)Text: if (a < b && b > c) { return "ok"; }; Mode: escape; Non-ASCII characters: keep; Escape quotes: noif (a &lt; b &amp;&amp; b &gt; c) { return "ok"; }

FAQ

What is the escape character HTML relies on?

The ampersand. Every HTML entity starts with & and ends with a semicolon, for example &lt; for the less-than sign. There is no backslash escape in HTML itself.

Which characters must I escape in HTML?

Always & and <. Also escape > in text for safety, and escape " or ' inside attribute values depending on which quote wraps the value.

Is it ' or ' for an apostrophe?

&#39; works in every HTML and XML parser. &apos; is valid in HTML5 and XML but unknown to HTML 4, so the numeric form is the safe choice. Python writes &#x27;, which is the same character.

How do I escape HTML in JavaScript?

Replace & first, then <, > and quotes, or set textContent instead of innerHTML so the browser does the escaping for you. Never build markup from user text without one of these steps.

Does escaping HTML stop XSS?

It stops injection in text and quoted attribute contexts. It does not protect URLs, script blocks, inline event handlers or CSS, which need their own encoding or a sanitizer.

Why does my page show &amp; instead of &?

The text was escaped twice. Decode it once with Unescape mode, store the raw value, and escape only when writing it into the page.

Is my text uploaded anywhere?

No. The conversion runs in your browser, so pasted text stays on your device.

How do I escape text for HTML?

Paste the text, keep the direction on escape and copy the result. The html escape text step replaces the five special characters (ampersand, less-than, greater-than, double quote and single quote) with entities, so the text shows up literally instead of being read as markup.

What is an HTML code escape?

An html code escape is a character reference, either a named entity or a numeric reference, that lets a reserved character appear as text instead of markup. This tool does that html code escape and the reverse.

Sources and references