# HTML Entities & Special Characters

> How to show characters that HTML treats as code, like the angle brackets and the ampersand, by escaping them into entities.

Subject: HTML | Lesson 4 of 42 | 5 min read
Interactive lesson: https://codewithanimation.in/html/html-entities
Previous: [Tags, Elements & Attributes](https://codewithanimation.in/html/elements-tags-attributes.md) | Next: [Headings & the Outline](https://codewithanimation.in/html/headings-and-outline.md)

## What it is

A few characters are part of HTML's own syntax. `<` starts a tag, `&` starts an entity, and `"` delimits an attribute value. If you type those literally as content, the browser tries to read them as markup instead of showing them.

An `entity` is the escaped form of such a character. Every entity starts with an ampersand and ends with a semicolon, like `&lt;` for `<` or `&amp;` for `&`. You write the entity, and the browser renders the single real character.

## Why it matters

The classic version of this bug is trying to show a code example in a tutorial. You type `The <strong> tag` and the word and its brackets vanish, because the browser turned `<strong>` into a real element. Entities are how you put literal HTML, math, and symbols on the page as text.

It is also a correctness issue in everyday content. An unescaped ampersand in a sentence or a URL can quietly confuse the parser, so knowing which characters to escape keeps your text reliable.

## How it works

To show a reserved character as text, replace it with its entity: `<` becomes `&lt;`, `>` becomes `&gt;`, and `&` becomes `&amp;`. Inside an attribute value you also escape the matching quote with `&quot;` or `&apos;`. The ampersand is the one people forget, and it is the most important, because it is what begins every entity.

Entities come in two forms. A `named` entity like `&copy;` is easy to read, but not every character has a name. A `numeric` entity works for any Unicode character at all: decimal `&#169;` or hexadecimal `&#xA9;` both render the copyright sign, exactly like `&copy;`.

`&nbsp;` is a special one: a non-breaking space that keeps two words or a label and its value from splitting across lines, like `Price:&nbsp;999`. Beyond these, because your files are UTF-8, you can usually just type symbols such as the copyright sign, arrows, or the euro directly and they render fine.

## Common mistake: Your code example disappears from the page

Writing `Use the <strong> tag` in your content makes the browser create a real `<strong>` element, so the brackets and often the text vanish instead of showing. To display tags as text, escape the brackets: `Use the &lt;strong&gt; tag`. The same applies any time you want to show literal HTML on the page.

## Tip: Escape the syntax characters, type the rest directly

In a UTF-8 document you only really need entities for the characters HTML reserves (`<`, `>`, and `&`) and for `&nbsp;`. Symbols like the copyright sign, arrows, and currency can be typed as the real character. And whichever form you use, remember every entity ends in a semicolon, since a missing semicolon is a common reason one fails to render.

## Try it: Code in, glyph out

On the left, the entities you type inside real content. On the right, the single character the browser renders for each one.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/html-entities

## Check yourself

### Question 1

You want the text "the <header> element" to appear on the page. What do you write?

- A. the &lt;header&gt; element
- B. the <header> element
- C. the (header) element

Correct answer: A

Escape the angle brackets so the browser shows them as text: `&lt;` for `<` and `&gt;` for `>`. Otherwise `<header>` is parsed as an actual element.

- Why not B: The browser reads `<header>` as a real element, so the brackets do not show as text.
- Why not C: Swapping the brackets changes the text. Escaping with entities shows the real angle brackets.

### Question 2

Which character do you escape as &amp;?

- A. The ampersand &, because it is what starts every entity
- B. The at sign @
- C. The hash #

Correct answer: A

`&` begins an entity, so to show a literal ampersand you write `&amp;`. It is the character people most often forget to escape.

- Why not B: The at sign has no special meaning in HTML; you can type it directly.
- Why not C: The hash is fine as a literal character in content.

### Question 3

Both &copy; and &#169; render the © sign. What does the numeric form give you?

- A. It works for any Unicode character, even ones with no name
- B. It renders faster than the named form
- C. It is the only valid way to write an entity

Correct answer: A

Named entities like `&copy;` are readable but only exist for some characters. Numeric entities (`&#169;` decimal or `&#xA9;` hex) can represent any Unicode character.

- Why not B: There is no meaningful speed difference; both produce the same character.
- Why not C: Named entities are perfectly valid; they are just limited to characters that have a name.

## Remember this

- Reserved characters (`<`, `>`, `&`, and `"` in attributes) must be escaped, or the browser reads them as HTML.
- An entity starts with `&` and ends with `;`: `&lt;` is `<`, `&gt;` is `>`, `&amp;` is `&`.
- Numeric entities like `&#169;` or `&#xA9;` work for any Unicode character; named ones like `&copy;` just read more clearly.
- `&nbsp;` is a space that never breaks across lines; in UTF-8 you can type most other symbols directly.
