Entities

HTML entities, derived from SGML, represent special characters using codes that begin with & and end with ;, ensuring correct display of symbols.

HTML Entities

HTML entities are used to represent characters that may not be available on a standard keyboard. They are commonly utilized for:

  • Copyright and trademark symbols (©, ™)
  • Special characters from different languages (á, ñ, €)
  • Mathematical notations (∞, ≠)
  • Symbols like bullets and section marks (§, •)

Example

This text contains a copyright symbol © and a euro symbol €.
index.html
This text contains a copyright symbol © and a euro symbol €.

Ways to Represent Entities

  1. Character Entities
  2. Non-Breaking Space

Character Entities

Some characters are reserved in HTML and need to be represented using entities to prevent conflicts with HTML tags.

  • The entity format follows this pattern:
index.html
&entity_name;
  • Numeric references use this format:
index.html
&#entity_number;

For instance, to display <, you can use &lt; or &#60;.

Entity names are generally easier to remember compared to entity numbers.

Character entities start with &# and can either be:

  • A decimal reference number representing the Unicode decimal code (e.g., &#169; for ©).
  • A named entity for widely used symbols (e.g., &copy; for ©).

Non-Breaking Space

One of the most frequently used entities is the non-breaking space.

This entity prevents automatic line breaks, ensuring words remain together in a sentence.

The non-breaking hyphen (&#8209;) ensures hyphenated words stay on the same line.

Common HTML Entities

SymbolDescriptionEntity NameEntity Number
 Non-breaking space&nbsp;&#160;
<Less than&lt;&#60;
>Greater than&gt;&#62;
&Ampersand&amp;&#38;
"Double quotation mark&quot;&#34;
'Single quotation mark&apos;&#39;
¢Cent&cent;&#162;
£Pound&pound;&#163;
¥Yen&yen;&#165;
Euro&euro;&#8364;
©Copyright&copy;&#169;
®Registered trademark&reg;&#174;
Entity names are case-sensitive.

Combining Diacritical Marks

A diacritical mark is a small symbol added to a letter.

Accents such as grave ( ̀ ) and acute ( ́ ) modify letters, forming characters that may not exist in certain character sets.

MarkCharacterConstructResult
```aa&#768;à
'aa&#769;á
^aa&#770;â
~aa&#771;ã
```OO&#768;Ò
'OO&#769;Ó
^OO&#770;Ô
~OO&#771;Õ

Using Character Entities in HTML

Character entities can be included directly in HTML like this:

This text contains a copyright symbol © and a euro symbol €.
index.html
This text contains a copyright symbol &copy; and a euro symbol &euro;.

Conclusion

HTML entities are essential for representing characters that aren't directly available on a keyboard or could cause conflicts with HTML tags. They can represent special symbols like copyright (©), trademark (™), currency symbols (€, £), and even mathematical notations.