HTML Encoder / Decoder Tool
Encode (escape) or decode (unescape) text for HTML. Prevents XSS.
Your Security Matters: Client-Side Processing
- All operations happen in your browser.
- Your data, images, files, keys, or passwords are never stored or sent to our servers.
- We don't track or monitor your generated content.
What is HTML Encoding (HTML Escaping)?
HTML encoding, also known as **HTML escaping**, is the process of converting special characters into their corresponding **HTML Entities**. This is essential because HTML uses characters like <, >, &, and " to define its structure (tags and attributes).
The Problem: If you want to *display* these characters as plain text (e.g., to show a code snippet like <p>Hello</p>), you cannot just type them directly. The browser will try to *interpret* them as HTML code, breaking your page layout or, even worse, creating a security vulnerability.
The Solution: You must "escape" them. The browser renders entities as the character they represent, not as code.
<becomes<>becomes>&becomes&"becomes"'becomes'(or')
- Preventing XSS Attacks: This is the most critical use case. If you display user-provided text (like a comment) on your page, an attacker could input
<script>...</script>. By **HTML escaping** this input, the browser will *display* the text<script>...</script>instead of *executing* the malicious script. - Displaying Code Snippets: To show HTML, XML, or any source code on your web page so users can read it.
- Handling Special Characters: For displaying characters not on your keyboard, such as the copyright symbol (
©for ©) or a non-breaking space ( ).
HTML Encode/Decode Examples
Loading HTML examples...
HTML Encoding Best Practices & Key Concepts
Encode on Output, Not on Input
A common mistake is encoding data *before* storing it in a database. The best practice is to store raw, clean data and **only encode it at the moment you render it** into an HTML page. This keeps your data portable (e.g., for JSON APIs) and ensures you apply the correct encoding for the correct context.
Context is Key
Not all encoding is the same. Escaping for the inside of an HTML tag (like ...) is different from escaping for an HTML attribute (like <input value="...">), where you must also escape quotes. For JavaScript (in an <script> block), you need JS string escaping. This tool focuses on standard HTML body escaping.
Use <pre> and <code> for Code
When displaying code, simple encoding isn't enough to preserve formatting (like whitespace and line breaks). For best results, wrap your *encoded* code snippet in a <pre> tag (to preserve whitespace) and a <code> tag (for semantic meaning): <pre><code>...your encoded content...</code></pre>.