HTML
π HTML Character Entities
πΉ What Are HTML Entities?
In HTML, some characters have special meanings.
For example:
- < β interpreted as the start of a tag
- > β interpreted as the end of a tag
- & β used to define special character codes
π If you write these characters directly, the browser may treat them as HTML code instead of plain text.
π Solution:
These characters must be written in a special format:
- &name; (named entity)
- &#number (numeric entity)
This way, they can be safely displayed on the page.
πΉ Types of Entity Syntax
1 Named Entities
HTML
< > &
π Easy to read and the most commonly used method.
2 Numeric Entities
HTML
< <!-- decimal -->
< <!-- hexadecimal -->
π Both represent the < character.
3 Commonly Used Characters
HTML
Character Entity (Name) Entity (Number) Description
< < < Less-than sign
> > > Greater-than sign
& & & Ampersand
" " " Double quote
' ' ' Single quote
space   Non-breaking space
4 Usage Examples
HTML
<p>5 < 10 and 10 > 5</p>
<p>Tom & Jerry</p>
<p>Display: "Hello World"</p>
π Browser output:
- 5 < 10 and 10 > 5
- Tom & Jerry
- Display: "Hello World"
5 Non-Breaking Space ( )
Normally in HTML, multiple spaces are displayed as a single space.
π When you use :
- The space is preserved
- Line breaks are prevented
Example
HTML
<p>10 km/h</p>
π Browser output:
- 5 < 10 and 10 > 5
- Tom & Jerry
- Display: "Hello World"
π β10β and βkm/hβ will not be split into different lines.
6. Using Special Symbols
You can also display symbols that are not available on the keyboard:
HTML
<p>Price: €50</p>
<p>Arrows: → ←</p>
π Output:
- Price: β¬50
- Arrows: β β
7. Important Notes
- Entity names are case-sensitive
- Always end entities with a semicolon (;)
- Not all characters have a named entity
- π In such cases, use numeric codes
Summary
- HTML Entities are used to safely display special characters
- Characters like <, > and & cannot be written directly
Two formats:
-
<&name;>β Keyboard input -
<&#number;>β Keyboard input -
< >is especially useful for spacing and preventing line breaks
