The Complete Guide to HTML Entity Encoding: Preventing XSS & Escaping Special Characters
Learn how to encode and decode HTML entities. Prevent Cross-Site Scripting (XSS), safely render code snippets, and master named and numeric character references.
Overview
In HTML, certain characters are reserved by the parser for markup syntax (such as < and > for opening and closing tags). When raw text contains these symbols, the browser interprets them as HTML tags rather than text content.
HTML Entity Encoding replaces reserved and special characters with predefined character references, ensuring safe display and preventing Cross-Site Scripting (XSS) vulnerabilities.
Our HTML Entity Converter runs locally in your browser to instantly encode or decode HTML entities with zero data leakage.
Why HTML Escaping is Critical for Web Security
Unsanitized user input rendered directly into the DOM is the leading cause of Cross-Site Scripting (XSS) attacks. For example, if a comment form accepts raw script tags, direct rendering allows an attacker to execute malicious scripts inside other users' sessions. When HTML-escaped, this string transforms into safe entities:
<script>alert(document.cookie)</script>The browser displays the exact characters without interpreting or executing the code.
Standard Named HTML Entities
| Raw Character | Named Entity | Decimal Entity | Hex Entity | Description |
|:---:|:---:|:---:|:---:|:---|
| & | & | & | & | Ampersand |
| < | < | < | < | Less-than sign |
| > | > | > | > | Greater-than sign |
| " | " | " | " | Double quotation mark |
| ' | ' | ' | ' | Apostrophe / Single quote |
| Space | |   |   | Non-breaking space |
| © | © | © | © | Copyright symbol |
| ™ | ™ | ™ | ࡊ | Trademark symbol |
Step-by-Step Instructions
Ready to calculate or convert?
Use our zero-install, private html entity converter directly inside your browser. No registration required.