Lesson 14 of 51 · Module 2, lesson 8 of 9 · 4 min

Special characters and emoji

Write characters like < and & safely, and add symbols and emoji to a page.

What you'll learn

  • Which characters you must write in a special way in HTML
  • How to write symbols such as ©, €, → and a non-breaking space
  • How to add emoji to a page

Why this matters

The character < starts a tag. So what if you want to write "3 < 5" on your page? The browser may think a tag is starting. HTML has a way to write such characters safely, and the same system lets you add symbols that are not on your keyboard.

Character references

A character reference (often called an entity) is a short code that the browser turns into one character. It starts with & and ends with ;.

You writeYou seeUse it for
&lt;<A less-than sign in text
&gt;>A greater-than sign in text
&amp;&An ampersand ("and" sign) in text
&quot;"A double quote inside an attribute value
&nbsp;(a space)A space that never breaks the line
&copy;©Copyright
html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Special characters</title>
</head>
<body>
  <h1>Salt &amp; pepper</h1>
  <p>Use less than 5 g of salt: amount &lt; 5 g.</p>
  <p>To start a heading, type &lt;h1&gt;.</p>
  <p>Cook for 20&nbsp;minutes.</p>
  <p>&copy; 2026 Home Kitchen</p>
</body>
</html>

What you'll see: "Salt & pepper", the less-than sign, the text <h1> written out, and ©.

The page "Salt & pepper". The paragraphs read: "Use less than 5 g of salt: amount < 5 g.", "To start a heading, type <h1>.", "Cook for 20 minutes." and "© 2026 Home Kitchen".

Which ones do you really need?

Because your pages use UTF-8 (the <meta charset="UTF-8"> line), you can type almost any character directly: é, ñ, ü, ç, €, →, 中, ع. You only need references for:

  • &lt; for < and &amp; for & in text. (> is usually safe, but &gt; is fine too.)
  • &quot; when a double quote appears inside a double-quoted attribute value.
  • Invisible characters such as &nbsp;, which you cannot see when you type them.

The non-breaking space

&nbsp; is a space that the browser will not use to break a line. Use it between a number and its unit, so that "20" and "minutes" never end up on different lines: 20&nbsp;minutes. Do not use it to make extra space — that is a job for CSS.

Numbers instead of names

Every character also has a number. You can write it as &# + number + ;. For example &#8364; is €, and &#8594; is →. You will see this in old pages, and it works for characters that have no name. With UTF-8, typing the character directly is usually clearer.

Emoji

Emoji are characters too, so you can type them directly — on Windows press Windows key + . (full stop), and on macOS press Control + Command + Space to open the emoji picker.

html
<p>Tomato soup 🍅 is ready! 🎉</p>

Emoji look different on different phones and computers, because each system draws its own. And a screen reader reads their name aloud ("tomato", "party popper"), so use them to add warmth, not to replace words.

Try it yourself

  1. Select the example above and choose Try it.
  2. Change &lt; to a plain < in "type <h1>". What happens to the page?
  3. Add a line with an emoji and a euro price, such as Soup: 4 €.

In step 2 the browser treats <h1> as a real heading, and the rest of the text becomes a big heading.

Common mistakes

  • Writing < in text. The browser may start a tag and hide text. Fix: write &lt;.
  • Forgetting the semicolon, such as &copy. It may work, or may not. Fix: always end with ;.
  • Using many &nbsp; to push text sideways. It breaks on small screens. Fix: use CSS for space.
  • Meaning only in emoji, such as "Oven ⚠️ 🔥". Some readers hear only "warning, fire". Fix: write the words: "Warning: the oven is hot."

Check yourself

  1. How do you write the text <p> so that it shows on the page?
  2. Why can you type é or € directly in your pages?
  3. What does &nbsp; do?

Answers

  1. &lt;p&gt;
  2. Because the page uses UTF-8, which includes every character.
  3. It makes a space that never breaks the line.

Next: in this lesson you wrote &lt;h1&gt; to show code on a page. The next lesson shows the elements made for displaying code, keyboard keys and program output.

Chat with us on WhatsApp