HTML Escape

HTML

0 chars 0 lines 0 bytes

HTML · JS · JSON

0 chars 0 lines 0 bytes

HTML Escape – Convert Special Characters to HTML Entities & Unescape

A free online tool to convert HTML special characters to entities and back to the original characters.

Automate link and QR code creation with the API

HTML Escape converting HTML special characters to entities

Why HTML escaping matters

HTML escaping replaces characters that have a special meaning in HTML, such as <, >, &, " and ', with HTML entities like &lt;, &gt;, &amp;, &quot; and &apos;, so the browser shows them as text instead of reading them as markup. Turning entities back into the original characters is called unescaping.

Without escaping special characters, a browser may run user input as code. For example, outputting <script>alert('XSS')</script> as is runs the script, while escaping it displays the text literally on screen.

Escaping is required wherever user input is displayed, such as message boards, comments, and search results. Even when your server handles it, use this tool to inspect or test the result.

Characters to escape and entity codes

These characters must always be escaped in HTML.

Character Entity code Description
< &lt; Tag start, less-than sign
> &gt; Tag end, greater-than sign
& &amp; Start of an entity
" &quot; Double quote in attribute values
' &apos; Single quote in attribute values

< and > are read as tags, and & as the start of an entity, so handle them first. Double and single quotes are escaped because they can break the syntax inside attribute values.

Unescape: restore entities to original characters

Unescaping is the reverse of escaping. It turns entities such as &lt;, &gt;, and &amp; back into <, >, and &.

It is useful when you need to:

  • Restore entity strings from API responses or databases to HTML source
  • Edit escaped content imported from email templates or external systems
  • Debug strings that were double-encoded on the server

Use the Escape and Unescape buttons in the input panel to convert in either direction.

Output formats compared: HTML, JS, JSON

The same special character is escaped differently depending on where it is used.

  • HTML: Uses entities such as &lt;, &gt;, &amp;, &quot;. Best for text placed directly in HTML source.
  • JS: Wraps the HTML-escaped result in a template literal such as const html = `…`; and escapes \, ` and ${ inside it with a backslash. Use it to put an HTML snippet into JavaScript code.
  • JSON: Wraps the HTML-escaped result in a {"html": …} object and escapes double quotes and control characters according to the JSON standard. Use it for text in API responses or JSON files.

Switch between the HTML, JS, and JSON tabs in the result panel to copy the format you need.

Server-side escaping code by language

After checking the result with this tool, escape output automatically on the server in production.

Language Code
Java (Spring) HtmlUtils.htmlEscape(str)
Java (Commons Text) StringEscapeUtils.escapeHtml4(str)
JavaScript textContent / createTextNode()
Python html.escape(str)
PHP htmlspecialchars($str, ENT_QUOTES)
Go html.EscapeString(str)
Ruby CGI.escapeHTML(str)

Most template engines, such as Thymeleaf, Jinja2, and Blade, escape automatically in th:text and {{ }} syntax. Syntax that outputs raw HTML, such as th:utext or the |safe and |raw filters, must be validated manually.

Common HTML entities

These are the HTML entities most often used in practice.

Character Entity name Entity number Description
< &lt; &#60; Less than, tag start
> &gt; &#62; Greater than, tag end
& &amp; &#38; Ampersand
" &quot; &#34; Double quote
' &apos; &#39; Single quote
Space &nbsp; &#160; Non-breaking space
© &copy; &#169; Copyright sign
® &reg; &#174; Registered trademark
™ &trade; &#8482; Trademark sign
— &mdash; &#8212; Em dash

Named entities (&lt;) and numeric entities (&#60;) output the same character. Numeric entities can also represent characters that have no name.

Frequently Asked Questions

Yes, they serve different purposes. HTML escaping converts special characters into forms like &lt; and &amp; so they are not read as tags or entities in an HTML document. URL encoding converts characters that are not allowed in URLs into percent-encoded forms like %2F and %20. When placing a link in an HTML attribute, URL-encode the parameter values first, then HTML-escape the entire URL.

Yes. If user input is placed directly in an HTML attribute value, a double quote can cut the attribute short and cause attribute injection. Non-HTML outputs such as email templates, PDFs, and CSV files also need escaping suited to each format.

Yes. th:text applies HTML escaping automatically, so even <b>test</b> is shown as literal tag characters. th:utext outputs raw HTML, so using it with untrusted data creates an XSS risk. Use it only for content from a clear source, such as content written by administrators.

No. Escaping, unescaping, and file reading all happen in your browser. Your code and data are never sent to Vivoldi servers.

By default, five characters are converted: <, >, &, ", and '. You can turn off each one in the options. Non-Latin scripts and emoji are safe to output as is in UTF-8 documents. If you need emoji as entities, turn on Convert emoji to HTML entities in the options. Other characters are not converted.

Strictly speaking, no, though the terms are often used interchangeably. An HTML entity is a notation defined by HTML to represent a character, such as &lt; or &copy;. HTML escaping is the process of converting special characters into entities. In other words, the result of escaping is an HTML entity.

Guides for this tool