Entities in HTML
? Entities in HTML
HTML entities are special codes used to display reserved characters or symbols that would otherwise be interpreted as HTML code. They ensure characters like <, >, &, and others show correctly in the browser.
Why Use HTML Entities?
To display characters reserved in HTML (like
<and>)To show special symbols (©, ®, ™, arrows, etc.)
To include non-ASCII characters safely
How Entities Work
An entity starts with an ampersand &, followed by a code or name, and ends with a semicolon ;.
Common HTML Entities
| Character | Entity Name | Entity Number (Decimal) | Example HTML | Output |
|---|---|---|---|---|
< | < | < | <div> | <div> |
> | > | > | > | > |
& | & | & | & | & |
" | " | " | " | " |
' | '* | ' | ' | ' |
| © | © | © | © | © |
| ® | ® | ® | ® | ® |
| ™ | ™ | ™ | ™ | ™ |
*Note: ' is not officially supported in older HTML versions, but widely supported in XHTML and HTML5.
Example: Displaying Reserved Characters
<p>Use <h1> for main headings, not <div>.</p>Renders as:
Use <h1> for main headings, not <div>.
Using Numeric Entities
Decimal:
&#code;(e.g.,©for ©)Hexadecimal:
ode;(e.g.,©for ©)
Summary
| When to Use | Example |
|---|---|
| Show HTML reserved chars | <, >, & |
| Display special symbols | ©, ® |
| Include non-ASCII chars | ©, 😀 |
Want me to help you find the entity codes for specific symbols or explain how to encode whole blocks of text safely?