HTML from Scratch: HTML Special Characters. Lesson #4


Hi, friends! 
Today, I’ll talk about special characters in HTML — an essential part of any web document. You’ll learn:

  • why they are needed,
  • how to use them properly,
  • and, of course, find a handy table of special characters at the end of the article.

Ready? Let’s begin! 

Why Special Characters Are Needed in HTML

Special characters are unique symbols that either don’t exist on the keyboard or are misinterpreted by browsers when used directly. For example:

  • How to write the © symbol? Simply typing it in the code won’t work.
  • How to add multiple spaces in a row? HTML will ignore them, leaving only one space.
  • How to display HTML tags as text? If you just use < and >, the browser will treat them as commands, not text.

This is where special characters come to the rescue. Let’s look at some examples.

Example: How to Display HTML Tags





If you try to add the following code:

<html>  
  <head>  
    <title>Example</title>  
  </head>  
  <body>  
  </body>  
</html>  

the browser will treat it as part of the page, not plain text. To fix this, replace < and > with &lt; and &gt;. Here’s how it will look:

&lt;html&gt;  
  &lt;head&gt;  
    &lt;title&gt;Example&lt;/title&gt;  
  &lt;/head&gt;  
  &lt;body&gt;  
  &lt;/body&gt;  
&lt;/html&gt;  

Result:
<html>
<head>
<title>Example</title>
</head>
<body>
</body>
</html>

Convenient, isn’t it?

How to Add Spaces

Regular spaces in HTML can be tricky. If you want multiple spaces, use &nbsp;. For example:

word1&nbsp;&nbsp;&nbsp;word2    

Result:

word1   word2

How to Display Special Characters in HTML

To insert a special character, use its code. For example, the copyright symbol (©):

All rights reserved &copy; 2024.  

Result:
All rights reserved © 2024.

Popular Special Characters Table HTML

Character Code Description Example
& &amp; Ampersand &
< &lt; Less than <
> &gt; Greater than >
&quot; Double quotation marks
&apos; Apostrophe
© &copy; Copyright sign ©
® &reg; Registered trademark ®
&trade; Trademark
&euro; Euro
£ &pound; Pound £
¥ &yen; Yen ¥
° &deg; Degree °
± &plusmn; Plus-minus ±
× &times; Multiplication ×
÷ &divide; Division ÷
&mdash; Em dash
&ndash; En dash
  &nbsp; Non-breaking space (no visual output)

Try it yourself! Write a few lines of code using special characters and see how they work.

See you in the next lesson! 😊