Mudzinga

Confused by odd symbols or broken accents in your web pages? Learn how HTML entities fix special characters, protect your code, and keep your content clean. Read on to master the basics!

5 Minute Read

HTML Entities: Special Characters in Your Content

HTML Entities: Special Characters in Your Content

When you first start writing HTML, you quickly run into a problem: how do you show special characters like ©, <, > or emojis without breaking your page?

That’s where HTML entities come in. In this article, you’ll learn what HTML entities are, why they matter, and how to use them to safely display special characters in your web content.

By the end, you’ll be able to:

  • Show symbols (like ©, ®, €, ™) correctly
  • Display characters that normally belong to HTML (like < and >)
  • Avoid weird bugs caused by invisible characters

What is an HTML Entity?

An HTML entity is a special code that represents a character in your HTML page.

It usually looks like this:

&amp;something;

It always:

  • Starts with &
  • Ends with ;

There are two main types:

  1. Named entities – easy to read, like &amp; or &copy;
  2. Numeric entities – use numbers, like &#169; or &#128512;

Both types display the same character on the page; they’re just written differently in your code.


Why Do We Need HTML Entities?

HTML uses some characters for its own structure. For example:

  • < starts a tag
  • > ends a tag
  • & starts an entity

If you just type these characters normally, the browser might think you’re writing HTML, not text.

For example, this HTML:

<p>2 < 5</p>

might confuse the browser, because it thinks < 5 could be part of a tag.

To fix this, we write:

<p>2 &lt; 5</p>

Now the browser knows you want to show the < symbol, not use it as HTML.


The Basic Must-Know HTML Entities

Here are some of the most commonly used entities you’ll see all the time:

Character Named Entity Numeric Entity Description
& &amp; &#38; Ampersand
< &lt; &#60; Less-than sign
> &gt; &#62; Greater-than sign
" &quot; &#34; Double quote
' &apos; &#39; Apostrophe/quote

You’ll use these a lot when writing text that includes symbols, code examples, or quotes inside attributes.


Example 1: Showing HTML Code as Text

Let’s say you want to teach someone HTML and show <p>Hello</p> on your page, as text, not as a real paragraph.

If you write this:

<p><p>Hello</p></p>

The browser will actually see nested paragraph tags, not text.

Correct version with entities

<!-- Example 1: Showing HTML code as text -->
<p>Here is a paragraph tag: &lt;p&gt;Hello&lt;/p&gt;</p>

What’s happening?

  • &lt; becomes <
  • &gt; becomes >

What you’ll see in the browser:

Here is a paragraph tag: <p>Hello</p>

The code remains visible as text instead of being treated as real HTML.

Try it yourself:

  • Change Hello to your name
  • Add another example like &lt;h1&gt;Title&lt;/h1&gt;

Example 2: Adding Symbols and Copyright Notices

Web pages often use symbols like © (copyright) or ® (registered trademark). These might work if you copy-paste them, but using entities is safer and more reliable.

Here’s how to add a simple footer with a copyright symbol.

<!-- Example 2: Using © and ™ in a footer -->
<footer>
  <p>&copy; 2025 My Awesome Site &ndash; All rights reserved &trade;</p>
</footer>

What’s happening?

  • &copy; → © (copyright)
  • &ndash; → – (short dash, called an "en dash")
  • &trade; → ™ (trademark)

What you’ll see in the browser:

© 2025 My Awesome Site – All rights reserved ™

Try it yourself:

  • Change the year
  • Replace &trade; with &reg; to get ®

Here are a few more handy entities:

Symbol Entity Meaning
© &copy; Copyright
® &reg; Registered mark
&trade; Trademark
&euro; Euro currency
£ &pound; Pound sterling
¥ &yen; Yen symbol

Example 3: Using Entities Inside Attributes

HTML attributes often use quotes. For example:

<a href="#">Click "here"</a>

This usually works, but sometimes you need to escape quotes to avoid confusing the browser, especially in more complex situations.

Here’s a safe way using &quot; for double quotes.

<!-- Example 3: Escaping quotes inside an attribute -->
<a href="#" title="Click &quot;here&quot; to learn more">
  Hover over this link
</a>

What’s happening?

  • The title attribute is wrapped in double quotes: "..."
  • Inside it, we want to show actual double quotes around the word here
  • &quot; turns into " in the browser

What you’ll see when you hover:

Click "here" to learn more

Try it yourself:

  • Change the word here to another word
  • Add an apostrophe too, using &apos; if needed

Example 4: Emojis and Numeric Entities

You can also use HTML entities to show emojis using numeric codes.

Here’s a fun example:

<!-- Example 4: Using numeric entities for emojis -->
<p>Welcome to my site! &#128512;</p>   <!-- 😀 grinning face -->
<p>We love HTML entities &#10084;&#65039;</p> <!-- ❤️ red heart -->

What’s happening?

  • &#128512; displays 😀
  • &#10084;&#65039; together display ❤️

Numeric entities are useful when:

  • There is no simple named entity
  • You’re copying character codes from a reference table

Try it yourself:

  • Search for "emoji HTML code" online
  • Replace the numbers with codes for your favorite emojis

Named vs Numeric: Which Should You Use?

For most beginners, named entities are easier to remember:

  • &copy; is more readable than &#169;
  • &euro; is more readable than &#8364;

However, numeric entities are helpful when:

  • No named version exists for a character
  • You’re using many emojis or rare symbols

You can safely mix both types in the same page.


Common Gotchas and How to Avoid Them

1. Don’t double-escape characters

If you write:

<p>Use &amp;lt; and &amp;gt; to show angle brackets.</p>

You’ll actually see this:

Use < and > to show angle brackets.

Why? Because &amp;lt; becomes &lt;, not <.

You usually only want one level of entity, like this:

<p>Use &lt; and &gt; to show angle brackets.</p>

2. Always escape <, >, and & in code examples

Any time you show HTML as text on a page, remember to:

  • Replace < with &lt;
  • Replace > with &gt;
  • Replace & with &amp;

This keeps your examples safe and visible.


Try It Yourself: Mini Practice Exercise

Create a simple HTML file and add the following:

  1. A heading that says: Learning & Loving HTML (make sure the & shows correctly)
  2. A paragraph that shows this exact text: <div>Not really a div</div>
  3. A footer that says: Made with ♥ in 2025 using an entity for the heart

You might end up with something like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>HTML Entities Practice</title>
</head>
<body>
  <h1>Learning &amp; Loving HTML</h1>

  <p>Here is fake HTML: &lt;div&gt;Not really a div&lt;/div&gt;</p>

  <footer>
    <p>Made with &#10084; in 2025</p>
  </footer>
</body>
</html>

Open this file in your browser and check that everything looks right. If it does, that’s a big win—you’re successfully using HTML entities.


Quick Recap and What’s Next

Here’s what you learned:

  • HTML entities let you safely show special characters in your content.
  • They always start with & and end with ;.
  • Use entities for characters HTML uses itself: <, >, &, quotes.
  • Use named entities for common symbols like &copy;, &euro;, &trade;.
  • Use numeric entities when there’s no named version or for emojis.

Learning this may feel a bit strange at first, but you’ve just unlocked a powerful tool for writing clean, reliable HTML.

From here, you can:

  • Explore more entities on reference sites like MDN or W3Schools
  • Practice by adding symbols, emojis, and code examples to your own pages

Every time your special characters show up correctly, that’s proof you’re thinking like a web developer. Keep experimenting and building!

About Percy Mudzinga

This article was automatically generated by an AI-powered blog system built by Percy.
Percy Mudzinga is a Senior Full-Stack Software Engineer based in Harare, Zimbabwe, with nearly a decade of experience building enterprise web and mobile applications. He specializes in React, Vue.js, Flutter, and Node.js.

Never Miss an Update

Subscribe to our newsletter and get the latest articles delivered directly to your inbox every week.

No spam, unsubscribe anytime. We respect your privacy.

© 2025 Mudzinga. All rights reserved.