HTML Encoder / Decoder

Online HTML Encoder & Decoder

Our free online HTML Encoder & Decoder converts special characters to HTML entities and decodes them back. Essential for preventing XSS attacks and displaying special characters safely in HTML.

Features:

  • Standard Encoding: Encode < > & " ' and other special characters.
  • Full Encoding: Convert ALL characters to their numeric HTML entities.
  • Smart Decoding: Decode both named (&amp;) and numeric (&#38;) entities.
  • XSS Prevention: Safely encode user input before displaying in HTML.
  • Secure & Private: All encoding/decoding happens locally in your browser.

1. What is HTML Encoding?

HTML encoding converts characters that have special meaning in HTML into their entity equivalents. This prevents browsers from interpreting the characters as HTML markup. For example, < becomes &lt; so it displays as a less-than sign instead of starting a tag.

2. Essential HTML Entities

&lt; → < (less than)
&gt; → > (greater than)
&amp; → & (ampersand)
&quot; → " (double quote)
&apos; → ' (single quote/apostrophe)
&nbsp; → non-breaking space

3. XSS Prevention

Cross-Site Scripting (XSS) attacks inject malicious scripts into web pages. HTML encoding user input prevents scripts from executing. Always encode: user comments, form inputs, URL parameters, and any untrusted data.

4. Named vs Numeric Entities

Named: &copy; → © (easier to read)
Decimal: &#169; → © (numeric code)
Hexadecimal: &#xA9; → © (hex code)
Numeric entities work for any Unicode character.

5. When to Encode

• Displaying user-generated content
• Showing code snippets in HTML
• Including special characters in attributes
• Preventing markup interpretation
• Email templates with special characters


This HTML encoding tool helps developers prevent XSS attacks and display special characters safely.

100% client-side processing ensures your content remains private.

Related Tools

url-encoder-decoder

base64-encoder-decoder

html-formatter

Understanding HTML Encoding & Security

The Importance of Context:

Different contexts require different encoding:
HTML Body: Encode < > &
HTML Attributes: Also encode " '
JavaScript: Use JavaScript escaping
CSS: Use CSS escaping
URLs: Use URL encoding

Common XSS Attack Vectors:

Script Injection: <script>alert('XSS')</script>
Event Handlers: <img onerror="alert('XSS')">
URL Schemes: <a href="javascript:alert('XSS')">
CSS: style="background:url(javascript:...)"

Special HTML Entities:

&copy; © Copyright
&reg; ® Registered
&trade; ™ Trademark
&euro; € Euro
&pound; £ Pound
&hearts; ♥ Heart

Best Practices:

• Always encode output, never trust input
• Use context-appropriate encoding
• Implement Content Security Policy (CSP)
• Use frameworks with auto-escaping
• Validate and sanitize on the server side too