·5 min read·Blog

HTML Entity Encoder: What HTML Entities Are and When to Use Them

&lt; looks like nonsense but it's how you display < in HTML without the browser treating it as a tag. Here's the complete guide to HTML entities and when you actually need them.

Why HTML entities exist

HTML uses angle brackets < and > for tags, and the ampersand & for entities themselves. If you want to display these characters as literal text on a page — not as HTML structure — you need to escape them:

  • &lt; displays as: <
  • &gt; displays as: >
  • &amp; displays as: &
  • &quot; displays as: "
  • &apos; displays as: ' (HTML5 only; use &#39; for broader support)

Without escaping, <script>alert(1)</script> written in page content would execute as JavaScript — this is how XSS (Cross-Site Scripting) attacks work. Properly escaping user-supplied content before rendering it in HTML is a critical security practice.

Encode HTML entities instantly with the free HTML entity encoder.

The five critical characters to always escape

CharacterEntity nameNumeric entityWhy escape it
<&lt;&#60;Opens HTML tags
>&gt;&#62;Closes HTML tags
&&amp;&#38;Starts entities
"&quot;&#34;Breaks quoted attributes
'&#39;&#39;Breaks single-quoted attributes

Named entities for special characters

HTML also provides named entities for characters that don't require escaping but are common typographic needs:

  • &nbsp; — non-breaking space (prevents line break between two words)
  • &copy; — © copyright symbol
  • &reg; — ® registered trademark
  • &trade; — ™ trademark
  • &mdash; — — em dash (the long dash)
  • &ndash; — – en dash
  • &hellip; — … horizontal ellipsis
  • &euro; — € euro sign
  • &pound; — £ pound sign

When you DON'T need entities

A common mistake: over-encoding everything. If your HTML file is saved as UTF-8 (which it should be in 2026), you can include most special characters directly:

  • © 2026 works fine in UTF-8 HTML — no need for &copy; 2026
  • Accented characters like é, ñ, ü can be written directly
  • Emoji work directly in UTF-8 HTML (though some email clients are different)

You only need entities for:

  1. The five critical characters that have syntactic meaning in HTML (<, >, &, ", ')
  2. Characters that aren't reliably available in the document's character encoding (rare for UTF-8)
  3. Non-breaking space (&nbsp;) and similar typographic controls

XSS prevention: the security angle

Cross-Site Scripting (XSS) is one of the most common web vulnerabilities. It occurs when user-supplied data is included in HTML output without escaping.

Unsafe pattern:

<!-- User searched for: <script>alert('xss')</script> -->
<p>Search results for: {{ user_query }}</p>

If user_queryisn't escaped, the browser executes the script. Safe:

<p>Search results for: &lt;script&gt;alert(&apos;xss&apos;)&lt;/script&gt;</p>

Most modern web frameworks (React, Vue, Angular, Django, Rails) auto-escape by default. The danger is when you bypass this with "raw" or "unsafe" output functions — dangerouslySetInnerHTML in React, v-html in Vue, |safein Django templates. Use these only when you control the content and have verified it doesn't contain user input.

Numeric entities

Every character can be referenced by its Unicode code point as a numeric entity:

  • Decimal: &#65; = A (Unicode code point 65)
  • Hexadecimal: &#x41; = A (0x41 hex = 65 decimal)

Numeric entities work for any Unicode character regardless of whether there's a named entity for it. They're useful for obscure symbols and special characters where the named entity isn't widely known.

Related tools


Written by Achraf A., founder of TheFreeAITools.

Browse by category

Not sure which tool you need? Start with a category.

Everything you can do — for free

No software to buy. No account to create. Just open a tool and get it done.

Work with images

Compress photos before sending them by email, resize pictures for social media, remove backgrounds, or pick the perfect color for a design project — all without installing any app.

Edit and format text

Count words and characters in an essay, compare two documents side by side, convert text to different formats, or generate placeholder text for a presentation.

Stay safe online

Create a strong unique password in one click, check how secure a password is, encode or decode data, and generate secure tokens — your data never leaves your device.

Calculate anything

BMI, loan repayments, unit conversions, date differences, and dozens of other everyday calculations — no spreadsheet or formula knowledge required.

The Free AI Tools is a free collection of 221+ online tools that work directly in your web browser — no download, no installation, no account required. Whether you need to compress an image for email, count words in an essay, generate a strong password, create a QR code for your business, or format JSON for development — you will find a simple, free tool here.

Every tool is privacy-first: your files, text, and data never leave your device. Tools cover image editing, text processing, developer utilities, security & encoding, SEO & web, design & CSS, and more.

☕ Support Us