HTML escape
Escape HTML special characters so text shows up literally inside HTML element content and quoted attribute values. It is the same operation as HTML encoding: characters like <, >, &, and " are replaced with entities so they display as text in browsers.
How it works
Encoding runs five replace calls in a fixed order, & first so the entities it inserts are not escaped a second time, turning &, <, >, " and ' into &, <, >, " and '. Decoding lets the browser's own HTML parser reverse the process: the text, with every < escaped first, is parsed inside a detached <textarea>, which never creates elements. Both run entirely in your browser.
Processing runs in your browser
All encoding and decoding happens locally in your browser tab. Our servers are not involved at any point.
Related operations
For percent-encoding URL components, try URL encode. To encode binary blobs or images as text, use Base64. For previewing escaped markup, see the Markdown preview.
Frequently asked questions
- What is the difference between HTML escaping and HTML encoding?
- They are the same operation. Both terms refer to replacing special HTML characters with their entity equivalents to prevent them from being interpreted as markup. 'Escaping' is the term more commonly used in a security context.
- When do I need to escape HTML?
- Any time you insert dynamic content into an HTML document, from a database, user input, or API response. Modern templating systems and frameworks auto-escape by default, but understanding manual escaping is still important.
- Does escaping prevent all XSS attacks?
- HTML escaping prevents injection into HTML text contexts. For other contexts (JavaScript, CSS, URLs, HTML attributes without quotes) different escaping rules apply. Always use context-appropriate escaping.
- How do I show HTML code on a web page?
- Escape the code, then place the result inside <pre><code> and </code></pre>. The browser displays <div> as the literal text <div> instead of creating an element.
Last reviewed September 30, 2026
Other pages for this tool
Related tools
- Background reading: Complete guide to developer tools