HTML Entity Encoder & Decoder

Convert special characters to HTML entities and vice versa. Encode and decode HTML safely!

Common HTML Entities

Character
Entity
Numeric
Description
<
&lt;
&#60;
Less than
>
&gt;
&#62;
Greater than
&
&amp;
&#38;
Ampersand
"
&quot;
&#34;
Double quote
'
&apos;
&#39;
Single quote
&nbsp;
&#160;
Non-breaking space
©
&copy;
&#169;
Copyright
®
&reg;
&#174;
Registered trademark
&trade;
&#8482;
Trademark
&euro;
&#8364;
Euro
£
&pound;
&#163;
Pound
¥
&yen;
&#165;
Yen
&bull;
&#8226;
Bullet
&hellip;
&#8230;
Ellipsis
&ndash;
&#8211;
En dash
&mdash;
&#8212;
Em dash

💡 Click any row to insert the entity into the input

About HTML Entity Encoder & Decoder

HTML entities are special codes used to represent characters that have special meaning in HTML or characters that cannot be easily typed on a keyboard. Our HTML Entity Encoder & Decoder makes it easy to convert between regular characters and their HTML entity equivalents, ensuring your HTML code is safe and displays correctly.

Features

  • Encode text to HTML entities (named or numeric)
  • Decode HTML entities back to regular text
  • Two encoding modes: special characters only or all characters
  • Switch input/output for quick reverse conversion
  • Comprehensive reference table of common HTML entities
  • Click to insert entities directly into input
  • Copy input or output to clipboard
  • Character count for output
  • Responsive design for all devices
  • Dark mode support
  • Multilingual interface

How to Use

  1. Enter your text in the input field
  2. Choose encoding mode: special characters only or all characters
  3. Click "Encode" to convert to HTML entities
  4. Or click "Decode" to convert HTML entities back to text
  5. Use "Switch" to swap input and output
  6. Click any entity in the reference table to insert it
  7. Copy the result to clipboard when done

What are HTML Entities?

HTML entities are special character sequences that begin with an ampersand (&) and end with a semicolon (;). They're used to display reserved characters in HTML or characters that aren't available on your keyboard.

There are two types of HTML entities:

  • Named entities: Use descriptive names (e.g., &lt; for <)
  • Numeric entities: Use character codes (e.g., &#60; for <)

Why Use HTML Entities?

  • Security: Prevent XSS (Cross-Site Scripting) attacks by encoding user input
  • Display Reserved Characters: Show <, >, & without breaking HTML
  • Special Symbols: Display copyright ©, trademark ™, and other symbols
  • International Characters: Display accented letters and non-ASCII characters
  • Compatibility: Ensure text displays correctly across all browsers

Common Use Cases

  • Displaying Code: Show HTML/XML code examples without executing them
  • User Input: Safely display user-generated content
  • Email Templates: Ensure special characters display correctly in emails
  • Database Storage: Store text with special characters safely
  • SEO: Use proper entities for meta tags and descriptions
  • Accessibility: Ensure screen readers interpret content correctly

Essential HTML Entities

Reserved Characters:

  • &lt; (<) - Less than sign
  • &gt; (>) - Greater than sign
  • &amp; (&) - Ampersand
  • &quot; (") - Double quotation mark
  • &apos; (') - Single quotation mark (apostrophe)

Common Symbols:

  • &nbsp; - Non-breaking space
  • &copy; (©) - Copyright symbol
  • &reg; (®) - Registered trademark
  • &trade; (™) - Trademark symbol
  • &euro; (€) - Euro sign
  • &pound; (£) - Pound sign

Encoding Modes Explained

Encode Special Characters Only:

Converts only HTML-reserved characters and common symbols to entities. Regular letters and numbers remain unchanged. This is the most common mode and produces readable output.

Input: Hello <world> & friends!
Output: Hello &lt;world&gt; &amp; friends!

Encode All Characters:

Converts every character to its numeric entity. Useful for maximum compatibility but produces less readable output.

Input: Hello
Output: &#72;&#101;&#108;&#108;&#111;

Security Considerations

HTML entity encoding is crucial for preventing XSS (Cross-Site Scripting) attacks. When displaying user-generated content, always encode it to prevent malicious scripts from executing. However, remember:

  • Encoding is not encryption - it doesn't hide data
  • Always validate and sanitize input on the server side
  • Use context-appropriate encoding (HTML, JavaScript, URL, etc.)
  • Don't rely solely on client-side encoding for security

Named vs Numeric Entities

Named Entities:

  • More readable and memorable
  • Limited set of predefined names
  • Not all browsers support all named entities
  • Example: &copy; for ©

Numeric Entities:

  • Work for any Unicode character
  • Universal browser support
  • Less readable for humans
  • Example: &#169; for ©

Programming Examples

JavaScript:

// Encode const encoded = text.replace(/[<>&"']/g, char => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;', "'": '&apos;' }[char])); // Decode const textarea = document.createElement('textarea'); textarea.innerHTML = encoded; const decoded = textarea.value;

PHP:

// Encode
$encoded = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');

// Decode
$decoded = html_entity_decode($encoded, ENT_QUOTES, 'UTF-8');

Python:

import html

import Breadcrumb from "@/components/Breadcrumb"; # Encode
encoded = html.escape(text)

# Decode
decoded = html.unescape(encoded)

Best Practices

  • Always encode user input before displaying it in HTML
  • Use named entities for common symbols (more readable)
  • Use numeric entities for special or international characters
  • Encode on output, not on input (store original data)
  • Use UTF-8 encoding to minimize the need for entities
  • Test your encoded content across different browsers
  • Don't double-encode (encoding already-encoded text)

Common Mistakes to Avoid

  • Forgetting to encode user input (security risk)
  • Encoding data before storing in database (store raw data)
  • Using wrong encoding for context (HTML vs JavaScript vs URL)
  • Not closing entities with semicolon
  • Double-encoding text multiple times
  • Using deprecated entities (use modern alternatives)

Frequently Asked Questions

When should I use HTML entities?

Use HTML entities when displaying special characters, reserved HTML characters, or user-generated content to prevent XSS attacks and ensure proper display.

Are HTML entities case-sensitive?

Named entities are case-sensitive (&copy; works, &COPY; doesn't). Numeric entities are not case-sensitive.

Can I use HTML entities in attributes?

Yes! HTML entities work in both element content and attribute values.

Do I need to encode spaces?

Regular spaces don't need encoding. Use &nbsp; only for non-breaking spaces.

What's the difference between &apos; and &#39;?

They both represent the apostrophe. &apos; is the named entity, &#39; is the numeric entity. Use &#39; for better browser compatibility.