🏷️ HTML Utility Suite

HTML Escape, Entity Encoder & HTML to Text Tool

Safely escape special HTML characters (<, >, &, "), encode HTML entities, decode unescaped strings, or strip tags to plain text.

Raw Input Code / Markup134 characters
Transformed Output

Why five characters cause most HTML problems

HTML gives special meaning to a handful of characters. A less-than sign starts a tag, an ampersand starts an entity, and quotes end attribute values. When text containing those characters is inserted into a page unescaped, the browser treats it as markup. At best a code sample disappears; at worst a user's comment containing a script tag runs in other visitors' browsers, which is a cross-site scripting (XSS) attack.

Escaping replaces each special character with an entity that the browser displays as the literal character without interpreting it: &lt; for the less-than sign, &gt; for greater-than, &amp; for the ampersand, &quot; for a double quote and &#039; for a single quote. The ampersand must be replaced first, otherwise the ampersands inside newly created entities would be escaped a second time.

Worked example: escaping a link

Escaping the markup <a href="x?a=1&b=2">Tom's</a> produces &lt;a href=&quot;x?a=1&amp;b=2&quot;&gt;Tom&#039;s&lt;/a&gt;. Placed inside a page, that string displays the original tag as visible text instead of creating a link.

Entity Encode works differently. It converts the five special characters and every non-ASCII character to a numeric entity based on its Unicode code point. For example é becomes &#233;, the euro sign becomes &#8364;, a double quote becomes &#34; and the emoji 😀 becomes the single entity &#128512; rather than two broken surrogate halves. Plain ASCII letters, digits and spaces are left as they are, so the output is safe to paste into an ASCII-only file or attribute.

Escaping depends on where the text goes

HTML escaping is correct for text placed between tags and inside quoted attribute values. It is not enough in other contexts, and this is the most common misunderstanding about it.

  • Inside a script block or an inline event handler, text needs JavaScript string escaping; HTML entities are not decoded inside script elements.
  • Inside a URL, such as an href query parameter, values need URL encoding (percent-encoding), and the whole URL still needs HTML escaping when placed in an attribute.
  • Inside a style block or style attribute, CSS has its own escaping rules.
  • Unquoted attributes are risky even when escaped, because a space can end the value. Always quote attribute values.

When you need this tool, and when your framework already does it

React, Vue, Angular, and most server template engines such as Jinja, Blade and Twig escape interpolated text automatically. You rarely need to escape by hand in those environments, and doing so causes double escaping, where readers see &amp;lt; on screen instead of a less-than sign. Manual escaping is most useful when writing documentation and blog posts that show code, building HTML strings in plain scripts, or preparing content for a CMS field that renders raw HTML.

Both reverse modes decode exactly one level, so &amp;lt; becomes &lt; and stops there. Unescape HTML reverses only the five entities that Escape produces (plus &#39; and &apos;), while Entity Decode uses the browser's own HTML parser and understands every named and numeric entity. Strip HTML to Text removes comments, drops the contents of script and style blocks and then removes the remaining tags with a pattern match. That suits quick extraction from known content but is not a sanitiser: never use tag stripping as protection against untrusted input. Use a dedicated sanitiser library such as DOMPurify when user HTML must be rendered.

HTML Escape & Encoder: frequently asked questions

Is escaping HTML the same as sanitising it?

No. Escaping turns all markup into visible text, so nothing is rendered as HTML. Sanitising keeps safe tags such as bold and links while removing dangerous ones like script and event handlers. Escape when you want to display code; sanitise when you need to render user-supplied formatting.

Do I need to escape the greater-than sign?

Strictly, only the less-than sign and ampersand are required in normal text, and quotes inside attribute values. Escaping the greater-than sign as well costs nothing and avoids edge cases, so most libraries do it by default.

What is the difference between &#039; and &apos;?

Both represent a single quote. &apos; is a named entity defined in XML and HTML5, but it was not part of HTML 4, so many tools prefer the numeric form &#039; or &#39; for maximum compatibility. Browsers today understand all three.

Should I store escaped text in my database?

Generally no. Store the original text and escape it at the moment you output it, for the specific context it is going into. Storing escaped text leads to double escaping and makes the data awkward to reuse in JSON, emails or search indexes.

Why do I see &amp;amp; in my page?

That is double escaping: text was escaped once, then escaped again before display. Find the layer that escapes already-escaped content, usually a template engine wrapping output that was escaped by hand, and remove one of the two steps.

All html & javascript utilities