Escape HTML

Safely escape HTML for innerHTML and attributes
ESCAPE
Output

About this tool

This tool escapes HTML code. Safely escape HTML code for use in innerHTML or HTML attributes. Supports three contexts: in innerHTML, attributes with single quotes, and attributes with double quotes. Easily escape ampersands, angle brackets, and quotation marks into safe HTML entities.
  • 100% free. No registration required.
  • Runs in the browser. No data is sent to the server.
Available via the API.

Limits

Unlimited usage via the browser.
When used via the API:
Plan Free - 1 000 requests / month
Plan Plus - 10 000 requests / month
Plan Pro - 100 000 requests / month
Plan Max - 300 000 requests / month
Learn more about plans and pricing.

Tips

  • Use the innerHTML context when inserting content between HTML element tags.
  • Use the single-quote attribute context when placing values inside attributes wrapped in single quotes.
  • Use the double-quote attribute context when placing values inside attributes wrapped in double quotes.
  • Escaping special characters prevents browsers from interpreting untrusted text as HTML markup or broken attributes.

Examples

  • in innerHTML: <div class="alert">Hello & Welcome</div> → &lt;div class="alert"&gt;Hello &amp; Welcome&lt;/div&gt;
  • attributes with single quotes: John's Profile & Settings → John&apos;s Profile &amp; Settings
  • attributes with double quotes: Click "Save" & Continue → Click &quot;Save&quot; &amp; Continue

Frequently Asked Questions

  • What is the Escape HTML tool?

    The Escape HTML tool is a free online tool that escapes HTML code. It converts special characters into safe HTML entities for web pages and templates.
  • What contexts are supported?

    The tool supports three contexts: in innerHTML, attributes with single quotes, and attributes with double quotes.
  • Why do different HTML contexts need different escaping?

    In innerHTML, angle brackets (< and >) must be escaped to prevent them from being parsed as tags, while quotes do not break element content. In attributes, quotation marks can close the attribute prematurely, so the matching quote delimiter must be escaped along with ampersands.
  • Is my HTML code sent to a server?

    No, HTML escaping runs directly in your browser. Your input is not sent to any server.

Something missing?

Feel free to contact us if you have any suggestions or found a bug.

Related tools

Remove HTML tagsMinify JavaScriptMinify CSSConvert colorsJSON encode/decode