HTML Entity Encoder

Encode/decode HTML entities

Mode:

Original Text

HTML Entities

About HTML Entity Encoder/Decoder

1What is it?

Encode text to HTML entities or decode entities back to text. Convert special characters like <, >, &, and quotes to their corresponding HTML entities (e.g., &lt;, &gt;) to prevent them from being interpreted as HTML code. Crucial for web security and displaying code snippets.

2Use Cases

  • Safely display HTML code on a webpage
  • Prevent XSS (Cross-Site Scripting) attacks
  • Encode special characters for XML files
  • Fix broken HTML caused by unescaped characters
  • Prepare content for database storage

3Examples

Encode tags

Input

<script>alert('hi')</script>

Output

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

Decode entities

Input

Copyright &copy; 2023

Output

Copyright © 2023

?Frequently Asked Questions

Why do I need to encode HTML?

Browsers interpret characters like < and > as HTML tags. If you want to display these characters literally (e.g., showing a code snippet), you must encode them. Encoding also prevents malicious scripts from executing if user input is displayed on a page.

What is the difference between named and numeric entities?

Named entities (like &copy;) use a keyword. Numeric entities (like &#169;) use the character's ASCII/Unicode number. Numeric entities are more universally supported, but named entities are easier to remember.