Reading history

HTML Entities and Special Characters

6 min read 2 views

Use HTML entities to escape <, > and &, show symbols like ©, € and ৳, keep words together with  , and understand named and numeric entities.

Some characters have a special job in HTML. A < starts a tag and an & starts a special code, so writing them directly in your text can break the page or produce the wrong result. HTML entities are short codes such as &lt; that display these characters safely. Entities also let you type symbols that are not on your keyboard, and the non-breaking space keeps words together on one line.

In this lesson you will learn

  • Which characters must be escaped and how
  • Named, decimal and hexadecimal entities
  • Currency, maths and arrow symbols
  • The non-breaking space and the soft hyphen
  • When to type characters directly with UTF-8

You should know HTML basics.

Reserved Characters and Common Entities

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HTML entities</title>
  <style>
    body { font-family: sans-serif; margin: 12px; font-size: 15px; }
    code { background: #eceff1; padding: 1px 4px; }
  </style>
</head>
<body>
  <!-- Characters that HTML would read as markup must be escaped -->
  <p>Use <code>&lt;p&gt;</code> for a paragraph.</p>
  <p>Tom &amp; Jerry, 5 &lt; 8 and 9 &gt; 2</p>
  <p title="She said &quot;hello&quot;">Hover me: the title contains quotes.</p>

  <!-- Named, decimal and hexadecimal forms of the same kind of thing -->
  <p>&copy; 2026 Core Tech ED &middot; &reg; &middot; &trade;</p>
  <p>Price: &#2547;500 (taka), &euro;5, &pound;4, &#x20B9;450 (rupee)</p>

  <!-- A non-breaking space keeps "10" and "km" on the same line -->
  <p>Distance: 10&nbsp;km. Temperature: 30&nbsp;&deg;C.</p>
</body>
</html>

Result

  • An entity starts with & and ends with ;. &lt; shows < and &gt; shows >, which is how you write about tags without the browser treating them as tags.
  • &amp; shows an ampersand. Always escape it in text and in URLs inside attributes, for example href="page?a=1&amp;b=2".
  • &quot; shows a double quote inside an attribute value that is itself wrapped in double quotes.
  • There are three ways to write a character: a name (&copy;), a decimal number (&#2547;, the Bangladeshi taka sign) or a hexadecimal number (&#x20B9;, the Indian rupee sign). Every Unicode character has a number, but only some have names.
  • &nbsp; is a non-breaking space. It looks like a normal space, but the line never breaks there, so “10 km” and “30 °C” always stay together.

Symbols and UTF-8

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Symbols and UTF-8</title>
  <style>
    body { font-family: sans-serif; margin: 12px; font-size: 15px; }
    td { padding: 3px 12px 3px 0; }
    .narrow { width: 110px; border: 1px solid #b0bec5; padding: 4px; }
  </style>
</head>
<body>
  <table>
    <tr><td>Maths</td><td>&times; &divide; &plusmn; &ne; &le; &ge; &frac12; x&sup2;</td></tr>
    <tr><td>Arrows</td><td>&larr; &uarr; &rarr; &darr; &harr;</td></tr>
    <tr><td>Punctuation</td><td>&ndash; &mdash; &hellip; &laquo;quote&raquo;</td></tr>
    <tr><td>Typed directly (UTF-8)</td><td>× ÷ → ৳ বাংলা 😀</td></tr>
  </table>

  <!-- &shy; is a soft hyphen: the word breaks there only if it must -->
  <p class="narrow">Internationali&shy;zation and accessi&shy;bility matter.</p>
</body>
</html>

Result

  • Entities exist for maths (&times;, &le;, &frac12;), arrows (&rarr;) and typography (&mdash;, &hellip;).
  • With <meta charset="UTF-8"> at the top of the page, you can also type any character directly: symbols, Bangla script and emoji all work. This is easier to read in the source, and modern editors save files as UTF-8 by default.
  • &shy; is a soft hyphen: an invisible break point. In the narrow box, “Internationalization” breaks at the soft hyphen and shows a hyphen; in a wide box it stays whole.
  • You still need entities for <, > and & in text, and for characters that are invisible or easy to confuse, such as the non-breaking space.

Most Used HTML Entities

CharacterNamedNumberDescription
<&lt;&#60;Less than
>&gt;&#62;Greater than
&&amp;&#38;Ampersand
“&quot;&#34;Double quote
‘&apos;&#39;Apostrophe
(space)&nbsp;&#160;Non-breaking space
©&copy;&#169;Copyright
€&euro;&#8364;Euro
৳none&#2547;Taka
×&times;&#215;Multiplication
→&rarr;&#8594;Right arrow

Common Mistakes

  1. Forgetting the semicolon, as in &copy 2026. Some old entities still work without it, but many do not.
  2. Using many &nbsp; in a row for spacing. Use CSS margin, padding or gap instead.
  3. Leaving out <meta charset="UTF-8">, so typed symbols turn into strange characters such as “é”.
  4. Writing a raw < in example code, which the browser may read as the start of a tag.

Practice Exercises

Exercise 1. Write HTML that displays exactly: if (a < b && c > d)

Show answer
<code>if (a &lt; b &amp;&amp; c &gt; d)</code>

Exercise 2. Write a footer line “© 2026 My Site”, keeping “My Site” from breaking across two lines.

Show answer
<footer>&copy; 2026 My&nbsp;Site</footer>

Frequently Asked Questions

Should I use entities or type characters directly?

With UTF-8, typing characters directly is fine and easier to read. Use entities for the reserved characters (<, >, &, quotes in attributes) and for invisible ones such as &nbsp;.

How do I find the number for a character?

Look it up in a Unicode chart or a character map tool. Its code point, such as U+09F3 for the taka sign, gives the hexadecimal entity &#x9F3;, which is the same character as &#2547;.

Summary

  • Escape <, > and & as &lt;, &gt; and &amp;.
  • Entities can be named, decimal or hexadecimal.
  • &nbsp; prevents a line break; &shy; allows one with a hyphen.
  • With UTF-8, most symbols can be typed directly.

Next: CSS calc(), min(), max() and clamp().

Lessons are also marked complete when you click Next.

Leave a Reply

Your email address will not be published. Required fields are marked *