HTML Entities Explained - Writing Special Symbols in Code

Imagine you are writing a lesson about HTML and you want to say: "The <p> tag creates a paragraph." The problem is that if you write <p> directly in your code, the browser thinks you want to create a paragraph - not display the tag as text.

That is the exact problem solved by HTML Entities. They are special ways to write symbols that conflict with HTML or cannot be typed directly from the keyboard.

Why Are There "Reserved" Symbols in HTML?

The browser reads the page and looks for specific signs to understand the structure:

  • The < sign means: "a tag starts here"
  • The > sign means: "a tag ends here"
  • The & sign means: "an entity starts here"

So if you want to display them as normal text, you cannot write them directly. The solution is to use a special code that the browser converts into the correct symbol when rendering.

One Rule That Explains Everything

Every HTML entity follows the same structure:

& + symbol_name + ;

Example: &lt;   -> displays <
Example: &gt;   -> displays >
Example: &amp;  -> displays &
Example: &copy; -> displays (c)

An entity always starts with & and always ends with a semicolon ;. The part in between is the symbol name.

Reserved Symbols - The Most Important

These symbols must always be written as entities when you want to display them as text:

Displayed Symbol Entity Code Name When to Use It
< &lt; Less Than Show HTML tags as text in explanations
> &gt; Greater Than Show HTML tags as text in explanations
& &amp; Ampersand Write & in text or URLs
" &quot; Quotation Mark Inside double-quoted attribute values
' &apos; Apostrophe Inside single-quoted attribute values

Non-Breaking Space - &nbsp;

The most famous HTML entity is &nbsp;, short for Non-Breaking Space.

Normally, the browser collapses repeated spaces into a single space. It can also break a line at a space if needed. &nbsp; solves both problems:

<!-- The browser shows only one space even if you type many -->
<p>Word          Word</p>

<!-- &nbsp; adds real spaces that are not collapsed -->
<p>Word&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word</p>

<!-- Prevent line break between two words -->
<p>Mr.&nbsp;Smith will not break</p>
Warning: Do not use &nbsp; for layout and alignment. That is CSS work. Use &nbsp; only when meaning requires preventing a line break between two words.

Other Common Symbols

Displayed Symbol Entity Code Use Case
(c) &copy; Copyright - in site footers
(R) &reg; Registered trademark
TM &trade; Trademark (not registered)
EUR &euro; Euro currency symbol
GBP &pound; British pound symbol
-> &rarr; Right arrow
<- &larr; Left arrow
OK &check; Check mark
&nbsp; &nbsp; Non-breaking space

Practical Example - Writing HTML Code Inside HTML

This is the most common case for entities: explaining HTML inside an HTML page. Here is how to write a sentence explaining the paragraph tag:

<!-- What you write in code -->
<p>The &lt;p&gt; tag creates a text paragraph in HTML.</p>

<!-- What the visitor sees in the browser -->
The <p> tag creates a text paragraph in HTML.

This is exactly what this site does in every lesson - every code sample you see is written with HTML Entities!

Frequently Asked Questions - FAQ

Are entities case-sensitive?

Yes. &lt; works, but &LT; does not. Always write entity names in lowercase.

Can I use a number instead of a name?

Yes. Each symbol has a Unicode number that can be written numerically. For example, &lt; can also be written as &#60;. The name is clearer and easier to read - use it whenever possible.

Do I need to memorize all these symbols?

No. You only need to memorize the five core ones: &lt;, &gt;, &amp;, &nbsp;, &copy;. You can easily look up the rest when you need them.

Great! You have now mastered how to write any special symbol in HTML safely. In the next lesson, we will explore symbols and emojis - hundreds of ready-made symbols you can use directly in your site.
Smart Editor

Write code and see the result instantly

Try it free