HTML Entity Encoder & Decoder - Escape Special Characters

Convert special characters to HTML entities (e.g., < to &lt;) and decode them back. Prevent XSS attacks and ensure safe HTML rendering.

100% In-BrowserZero UploadsNo SignupShareable Link

Encode special characters and astral Unicode symbols into safe HTML entities and decode named, decimal, and hex entities in a single pass immune to double-decoding.

About HTML Entity Encoder & Decoder - Escape Special Characters

An HTML Entity Encoder is a developer tool that converts characters with special meaning in HTML (like <, >, &, ") into their corresponding HTML entities (like &lt;, &gt;, &amp;, &quot;). This process, known as escaping, is crucial for web security and data integrity. It prevents the browser from interpreting these characters as code, thereby protecting against Cross-Site Scripting (XSS) attacks. Conversely, the decoder converts these entities back into their original characters. This tool supports named entities (e.g., &copy;), decimal entities (&#169;), and hexadecimal entities (&#xA9;).

Input Formats

  • Raw text with special characters
  • HTML code snippets
  • Strings with existing entities

Output Results

  • Escaped HTML string
  • Decoded plain text
  • Copy-ready result

Key Features

Prevent XSS: Sanitize user input to prevent Cross-Site Scripting attacks
Data Integrity: Ensure special characters render correctly in HTML
Bidirectional: Encode and Decode instantly with one click
Privacy: 100% Client-side processing; no server uploads
Comprehensive: Handles named, decimal, and hexadecimal entities
Safe Copying: Prevents broken layouts when copying code snippets
Developer Essential: Must-have for CMS and template development
Free & Fast: The best free fast HTML entity encoder for web developers
Shareable LinksShare encoded/decoded HTML snippets. (Limit: 5KB)

Who is this for?

Web Security

Developers sanitizing user-generated content before rendering it to the DOM to prevent script injection.

XSS preventionSanitizationInput validationSecurity

Content Management

Writers escaping code snippets to display them literally in blog posts or documentation.

Code displayEscaping HTMLDocumentationBlog post

Data Migration

Cleaning up database entries that contain mixed encoded and unencoded content.

Data cleanupDatabase migrationText processing

How to Use

1

Paste your text into the input area.

2

Select 'Encode' to escape special characters.

3

Select 'Decode' to revert entities to characters.

4

Copy the result.

Examples

Input

<script>alert('XSS');</script>

Output

&lt;script&gt;alert('XSS');&lt;/script&gt;

Common Errors & Pitfalls

  • Double encoding (e.g., &amp;lt;)
  • Forgetting to decode before editing
  • Confusing URL encoding with HTML encoding

Code Examples

JavaScript

function encode(str) {
  return str.replace(/[&<>'"/]/g, (char) => ({
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    "'": '&#39;',
    '"': '&quot;',
    '/': '&#x2F;'
  })[char]);
}

Frequently Asked Questions

Why do I need to encode HTML?
If you don't, hackers could use 'Cross-Site Scripting' (XSS) to attack your users. Encoding turns dangerous code into safe text that the browser just displays.
What characters are encoded?
I handle all the critical ones like <, >, &, ", and '. I can also encode emojis and copyright symbols if you need me to.
Is this different from URL encoding?
Yes! URL encoding (like %20) is for links. HTML encoding (like &amp;) is for webpage content. They are not interchangeable.
Can I decode multiple times?
Yes! If you have text that was encoded twice (like &amp;lt;), just click 'Decode' a few times until you see the original text.

Authoritative Sources & Citations