Website Tools

HTML Entities Explained – How to Show Code and Symbols Safely

Type “<b>” into a web page and it turns text bold instead of showing up. HTML entities are how you display special characters exactly as written.

In this article
  1. Why some characters need escaping
  2. When you need it
  3. How to encode or decode
  4. Escaping and security
  5. Useful symbol entities
  6. Showing code in a blog post
  7. Entities vs other encodings
  8. Double-escaped text

Why some characters need escaping

In HTML, a few characters have special meaning: “<” starts a tag, “&” starts an entity, and quotes end attribute values. To show them as normal text you write them as entities – short codes that the browser turns back into the character.

CharacterEntity
&&amp;
<&lt;
>&gt;
"&quot;
'&#39;
HTML Entity EncoderConvert <, >, &, quotes and other characters to HTML entities, or decode entities back to text. Named, decimal or hex style for non-ASCII characters.
Open the free tool

When you need it

  • Showing code on a page – tutorials, documentation, blog posts about HTML.
  • Text inside attributes – titles, alt text and data attributes containing quotes.
  • Company names with “&” – “Smith & Sons” should be written Smith &amp; Sons in HTML.
  • Old systems that only handle plain ASCII, such as some email templates.

How to encode or decode

  1. Open the HTML Entity Encoder.
  2. Paste your text and encode: the five special characters are always escaped.
  3. Optionally encode every non-ASCII character too – useful for systems that mangle accents or emoji.
  4. Choose named (&copy;), decimal (&#169;) or hex (&#xA9;) style.
  5. Switch to decode to turn entities back into readable text, including emoji.

Escaping and security

When a website displays text that users typed – comments, names, search terms – without escaping it, an attacker can type HTML or JavaScript that runs in other visitors’ browsers. This is called cross-site scripting (XSS) and is one of the most common web vulnerabilities. Modern frameworks escape output automatically, but hand-written templates and quick scripts often forget. The rule: escape any untrusted text before inserting it into HTML.

Useful symbol entities

SymbolEntity
©&copy;
®&reg;
™&trade;
– (en dash)&ndash;
non-breaking space&nbsp;

With UTF-8 pages, you can type most symbols directly; entities are only essential for the five special characters.

Showing code in a blog post

When you write a tutorial that includes HTML, encode the snippet and place it inside <pre><code> tags so line breaks and indentation are kept. In WordPress, the Code block does the escaping for you; in the Classic editor’s Text tab or in custom HTML blocks, paste the encoded version. Always preview the post to check that the code appears as text rather than being rendered.

Entities vs other encodings

HTML entities are for HTML. Web addresses use percent-encoding – see the URL Encoder. Binary data in text uses Base64. Using the wrong one is a common cause of broken links and garbled text.

Double-escaped text

If a page shows “&amp;” or “&lt;b&gt;” literally, the text was escaped twice. Decode once and check where your system escapes – it should happen exactly one time, at output.

HTML Entity EncoderConvert <, >, &, quotes and other characters to HTML entities, or decode entities back to text. Named, decimal or hex style for non-ASCII characters.
Open the free tool
Keep reading

Related articles

All articles
Dev

URL Encoding Explained – Why Spaces Become %20

Paste a link with spaces, “&” or Urdu text and it can break. URL encoding fixes this by turning special characters into safe % codes.

3 min read
Dev

What Is Base64 – and When Should You Use It?

Base64 shows up in emails, web pages, API keys and data URIs. It is simple once you see what problem it solves – and what it does not do.

3 min read
Dev

How to Clean Up Messy HTML Code (and Find Problems Faster)

HTML from page builders, email templates and “view source” is often one long line or a tangle of tags. Formatting it is the first step to understanding and fixing it.

3 min read