HTML Entity Encoder & String Escaper

Paste code or text to escape it for safe display in HTML, turning <, > and & into entities so your code snippet shows on the page instead of running. Optionally wrap it in <pre><code> for blogs and documentation. The same tool escapes strings for HTML attributes, XML, JavaScript, JSON, SQL, CSV, regular expressions and shell commands, and unescapes them again.

  • 100% free
  • No sign-up
  • Private & local
  • Works on mobile

Private by design: every calculation runs locally in your browser. Nothing you type is sent to a server or stored by us.

Why Escape Code for HTML?

If you paste code like <div class="note"> directly into a web page, blog post or CMS, the browser treats it as real HTML: the tags disappear, get rendered, or break your layout. To display code instead of running it, the special characters must be converted into HTML entities: < becomes &lt;, > becomes &gt;, and & becomes &amp;. This HTML entity encoder does this instantly, and can wrap the result in <pre><code> tags with a language class for syntax highlighters like Prism or highlight.js.

Escaping also matters for security. Inserting untrusted text into HTML, JavaScript or SQL without escaping for that context leads to cross-site scripting (XSS) and SQL injection. Every target language has its own escaping rules, which is why this tool supports nine of them.

How to Use the String Escaper

  1. Choose Escape or Unescape.
  2. Choose the target, meaning where the text will be used: HTML content, an HTML attribute, XML, a JavaScript or JSON string, SQL, CSV, a regex or a shell command.
  3. Paste your code or text. The escaped version appears instantly.
  4. For HTML, optionally wrap it in <pre><code>, add a language class, and convert tabs to spaces.
  5. Copy or download the result.

Escaping Rules by Language

TargetCharacters escapedExample
HTML content& < >a < b → a &lt; b
HTML attribute& < > " 'say "hi" → say &quot;hi&quot;
XML& < > " ' (the 5 predefined entities)' → &apos;
JavaScript\ ' " ` newlines, tabs, control chars, </scriptIt's → It\'s
JSON\ " control charactersC:\temp → C:\\temp
SQL' doubledO'Brien → O''Brien
CSVQuotes doubled; field quoted if neededa,"b" → "a,""b"""
Regex. * + ? ^ $ { } ( ) | [ ] \ / -1.5+2 → 1\.5\+2
Shell (bash)Wrap in single quotes; ' becomes '\''it's → 'it'\''s'

A Note on Security

Escaping is essential, but it's not the whole story. For SQL, always prefer parameterised queries / prepared statements over escaping strings yourself, as they're immune to injection. For HTML, use your framework's automatic escaping (React, Vue, Angular, Django and Rails templates all do this) and sanitise user-generated HTML with a library such as DOMPurify. Use this tool for documentation, code snippets, configuration and one-off data work.

Showing Code in Blogs and CMSs

WordPress, Ghost, Blogger and most content management systems have a "code" or "HTML" block. When you paste escaped code inside <pre><code>, readers see exactly the characters you intended. Add a language class such as language-html or language-js, and highlighters like Prism.js or highlight.js will colour it automatically. Converting tabs to spaces keeps indentation consistent across browsers and themes. The same escaping is useful when writing documentation, answering questions on forums, and pasting snippets into email newsletters, which often strip or mangle raw HTML.

Choosing the Right Target

Always escape for the exact context where text will be inserted. HTML content, attribute values, JavaScript strings inside a <script> tag and URL query values each have different dangerous characters. Escaping for the wrong one is a common source of both bugs and security holes. When one value passes through several layers, such as a JSON string inside an HTML attribute, escape for the innermost layer first, then the outer one.

Examples of Escaped Output

The code <a href="/?q=1&x=2">Link</a> becomes &lt;a href="/?q=1&amp;x=2"&gt;Link&lt;/a&gt; for HTML display. The JavaScript string It's "done" becomes It\'s \"done\". The SQL value O'Brien becomes O''Brien, and the regex text price: $9.99 (USD) becomes price: \$9\.99 \(USD\). Choosing the right target means the text is read exactly as written, with no characters interpreted as code, delimiters or special syntax.

Unescaping

Switch the mode to Unescape to reverse any of these transformations, which is useful when reading log files, debugging API responses and cleaning up data exported from other systems.

Frequently Asked Questions

How do I show HTML code on a web page?

Escape <, > and &, then place the result inside <pre><code>…</code></pre>. This tool does both.

What's the difference between this and the HTML Entities tool?

This tool escapes code for many languages. The HTML Entities Encoder/Decoder converts accents and symbols to named or numeric entities.

Do I need to escape quotes in HTML content?

Not inside element content, but yes inside attribute values. Choose the "HTML attribute" target.

How do I escape a backslash in JSON?

Double it: \ becomes \\.

Is my code uploaded?

No. Everything is processed in your browser.