HTML Encoder/Decoder

Encode and decode HTML entities


1. What are HTML Entities?

HTML entities are used to display reserved characters in HTML. They start with an ampersand (&) and end with a semicolon (;). This prevents the browser from interpreting these characters as HTML code.

2. How does it work?

Common Entities

  • & → &
  • < → &lt;
  • > → &gt;
  • " → &quot;
  • ' → &#39;

3. Examples

Ampersand

AT&T → AT&amp;T

HTML tags

<div>Hello</div> → &lt;div&gt;Hello&lt;/div&gt;

Quotes

Say "Hello" → Say &quot;Hello&quot;

4. Source Code

typescript
1const htmlEntities: Record<string, string> = {
2  '&': '&amp;',
3  '<': '&lt;',
4  '>': '&gt;',
5  '"': '&quot;',
6  "'": '&#39;',
7  '/': '&#x2F;',
8};
9
10const reverseHtmlEntities: Record<string, string> = {