Himanshu SharmaSoftware engineer
Let’s talk

HTML · Lesson 30 of 31

Special characters and entities

Write special characters in HTML with entities such as < & and ©, use UTF-8 for symbols and other languages, and avoid common escaping mistakes.

10 minGoing furtherUpdated 18 October 2026

By the end of this lessonShow reserved characters such as the less-than sign and the ampersand correctly, insert symbols with entities or UTF-8, and avoid invisible-character traps.

Why some characters are special

Browsers read HTML by looking for < to start a tag and & to start an entity. So if you simply write 5 < 10 or Tom & Jerry, you are asking the browser to guess whether you meant text or markup, and it may guess wrong. In particular < followed by a letter will be taken as the start of a tag, and the rest of your text may vanish.

To show those characters safely, you write entities.

What an entity looks like

An entity is a code for one character. It begins with & and ends with ;:

html
<p>5 &lt; 10 and 10 &gt; 5</p>
<p>Tom &amp; Jerry</p>
<p>&copy; 2026 Sunrise Bakery &mdash; all rights reserved</p>
<p>Price: &#8377;120 &nbsp;&nbsp;&nbsp; (three non-breaking spaces)</p>

There are two kinds:

  • Named: &lt;, &amp;, &copy;. Easier to read and remember.
  • Numeric: &#8377; (decimal) or &#x20B9; (hexadecimal) for any Unicode character, using its code number.

The ones you must know

You want Write
< &lt;
> &gt;
& &amp;
" (inside a double-quoted attribute) &quot;
' (inside a single-quoted attribute) &#39;
Non-breaking space &nbsp;

The first three matter most. If you are writing a tutorial that shows HTML code, every < in the displayed code must be written &lt;. (The code and pre elements do not turn off markup; entities are still needed.)

Handy symbols

&copy; ©, &reg; ®, &trade; ™, &mdash; —, &ndash; –, &hellip; …, &rarr; →, &larr; ←, &times; ×, &euro; €, &pound; £, &deg; °, &hearts; ♥.

You can often type the character instead

Entities were important when files were saved in limited encodings. Today, if you save your file as UTF-8 and declare it, you can type symbols directly:

html
<meta charset="utf-8">
<p>© 2026 · ₹120 · हिन्दी · café · 日本語</p>

Check that your editor saves as UTF-8 (most do by default). Entities are still required for the three reserved characters (<, >, &), and are useful for characters that are hard to type or easy to confuse, such as the non-breaking space.

Non-breaking space: use with care

&nbsp; is a space the browser will not collapse or wrap. It has proper uses: keeping a value and its unit together (10&nbsp;km) or a title and a name (Dr.&nbsp;Rao) so a line never breaks between them.

It is not a layout tool. Strings of &nbsp;&nbsp;&nbsp; to indent text or space out a menu break on different screens and cannot be styled. Use CSS margin and padding for that.

Escaping inside attributes

If a value contains the quote character that surrounds it, the attribute ends early:

html
<!-- Broken: the quote ends the value after "He said " -->
<img src="a.jpg" alt="He said "hello"">

<!-- Fixed -->
<img src="a.jpg" alt="He said &quot;hello&quot;">
<!-- or use different outer quotes -->
<img src="a.jpg" alt='He said "hello"'>

In URLs inside attributes, a bare & between query parameters should be &amp;: href="/search?q=bread&amp;page=2".

Invisible characters

Some characters have no visible shape yet still count: a zero-width space, a soft hyphen (&shy;) that allows a word to break, or a left-to-right mark. Text pasted from word processors or chat apps sometimes carries them in and can break spacing or searching. Our free Invisible Character Cleaner tool finds and removes them.

Common mistakes

  • A bare < or & in text, which swallows content or invalid markup.
  • Forgetting charset, so symbols turn into garbage.
  • Typing &copy without the semicolon. Browsers forgive some of these, but not all.
  • Using &nbsp; to lay out a page.
  • Showing code samples without escaping <.

Exercise

Write the HTML to show this sentence exactly as text: Use <strong> for important text & <em> for emphasis. Then add a copyright line for 2026.

Show one possible answer
html
<p>Use &lt;strong&gt; for important text &amp; &lt;em&gt; for emphasis.</p>
<p>&copy; 2026 Your Name</p>

Key points

  • The less-than sign, greater-than sign and ampersand have special meaning in HTML, so to show them as text you write &lt;, &gt; and &amp;.
  • An entity starts with & and ends with ;, using a name (&copy;) or a number (&#169;).
  • With meta charset="utf-8", you can type most symbols and any language directly.
  • is a space that does not wrap or collapse, but it is a poor tool for layout.
  • Inside attribute values, a double quote is written &quot; when it would end the value.

Check yourself

1. How do you show the text <p> on a page without creating a paragraph?
2. What does &amp; display?
3. What do you need to be able to type ₹ and हिन्दी directly in your HTML?
4. Why is using &nbsp; repeatedly to create spacing a poor idea?

Free tools for this lesson