100% FREE · NO SIGNUP

HTML Entity Encoder / Decoder

Convert special characters to HTML entities and back. Supports named entities, decimal codes, and hexadecimal codes.

Encoding Format

0
0

HTML Entity Reference

CharNameDecimalHexDescription

🚀 More Free Dev Tools

URL Encoder, Base64 Encoder, JSON Formatter, Regex Tester, and 25+ more tools.

Browse All Tools →

Free HTML Entity Encoder / Decoder

HTML entities are special codes used to represent characters that have a special meaning in HTML, or characters that cannot be easily typed on a keyboard. This tool converts between plain text and HTML entities instantly.

Why Encode HTML Entities?

Named vs Numeric vs Hex Entities

Code Examples

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

// JavaScript — Decode
function decodeHTML(str) {
  const textarea = document.createElement('textarea');
  textarea.innerHTML = str;
  return textarea.value;
}

// Python
import html
encoded = html.escape('<div>Hello & World</div>')
decoded = html.unescape('&lt;div&gt;Hello&lt;/div&gt;')

// PHP
$encoded = htmlspecialchars('<p>Hello</p>');
$decoded = htmlspecialchars_decode('&lt;p&gt;Hello&lt;/p&gt;');

Most Common HTML Entities

Frequently Asked Questions

What are HTML entities?

HTML entities are special codes used to represent characters with reserved meaning in HTML, such as < (less-than), > (greater-than), & (ampersand), and " (double quote). These characters would otherwise be interpreted as HTML syntax. Entities start with & and end with ;. For example, &lt; renders as < and &amp; renders as &.

How do I encode text for use in HTML?

Paste your text into the input field above and click Encode. The tool converts all special characters into their corresponding HTML entities. The most important characters to encode are < (&lt;), > (&gt;), & (&amp;), and " (&quot;). This ensures your content displays correctly and helps prevent cross-site scripting (XSS) vulnerabilities in web applications.

What is the difference between named and numeric entities?

Named entities use a descriptive name like &nbsp; (non-breaking space) or &copy; (©). Numeric entities use the character's Unicode code point: decimal like &#160; or hexadecimal like &#xA0;. Both refer to the same character. Named entities are more readable; numeric entities work for any Unicode character, even those without a named entity defined.

Do HTML entities prevent XSS attacks?

Yes. Encoding user-supplied input with HTML entities prevents cross-site scripting (XSS). If a user submits <script>alert('xss')</script>, encoding it as &lt;script&gt;... renders it as visible text rather than executing it. Always encode untrusted input before inserting it into HTML. Server-side encoding is more reliable than client-side for security-critical applications.

What are the most important HTML entities to know?

The five most critical entities are: &lt; (less-than <), &gt; (greater-than >), &amp; (ampersand &), &quot; (double quote "), and &apos; (single quote '). Common display entities include &nbsp; (non-breaking space), &copy; (©), &mdash; (—), &laquo; («), and &raquo; (»). These cover the vast majority of everyday HTML encoding needs.

Need AI-Powered Dev Tools?

Explore the MatrixClawAI API — automate your workflow with AI agents.

Explore API →

Related Tools