What is HTML Entity?
HTML Entity (HTML Character Entity) is a string that begins with an ampersand (&) and ends with a semicolon (;), used to represent special characters in HTML that would otherwise be interpreted as HTML code or are not easily typed on a keyboard.
Quick Facts
| Full Name | HTML Character Entity |
|---|---|
| Created | 1993 (with HTML specification) |
| Specification | Official Specification |
How It Works
HTML entities allow web developers to display reserved characters like <, >, &, and " that have special meanings in HTML markup. They also enable the display of characters not available on standard keyboards, such as copyright symbols (©), mathematical symbols (±), and characters from other languages. Entities can be written as named references (like &) or numeric references using decimal (&) or hexadecimal (&) codes. The HTML5 specification defines over 2,000 named character references.
Key Characteristics
- Starts with & and ends with ; (e.g., &)
- Named entities use descriptive names (e.g., ©)
- Numeric entities use decimal (©) or hex (©) codes
- Required for displaying reserved HTML characters
- Case-sensitive for named entities
- Over 2,000 named entities defined in HTML5
Common Use Cases
- Displaying HTML reserved characters (<, >, &, ", ')
- Inserting special symbols (©, ®, ™, €)
- Adding non-breaking spaces ( )
- Displaying mathematical symbols (±, ×, ÷)
- Including characters from other languages
Example
Loading code...Frequently Asked Questions
What is the difference between named and numeric HTML entities?
Named entities use descriptive words (like © for ©), making them easier to remember and read. Numeric entities use decimal (©) or hexadecimal (©) codes. Named entities are limited to those defined in the HTML specification, while numeric entities can represent any Unicode character.
When should I use HTML entities instead of typing characters directly?
Use HTML entities for: 1) Reserved HTML characters (<, >, &, ", ') that would be interpreted as markup, 2) Characters not available on your keyboard, 3) When you need consistent rendering across all systems regardless of character encoding, 4) Non-breaking spaces ( ) for layout control.
Are HTML entities case-sensitive?
Yes, named HTML entities are case-sensitive. For example, © (©) is valid, but © may not render correctly in all browsers. Numeric entities (both decimal and hexadecimal) are not case-sensitive for the 'x' prefix, so © and © are equivalent.
How do I display an ampersand (&) in HTML without it being interpreted as an entity?
Use the & entity to display a literal ampersand. Writing just & in HTML can cause parsing issues because the browser may interpret it as the start of an entity. For example, to show 'Tom & Jerry', write 'Tom & Jerry' in your HTML code.
What is the entity and when should I use it?
represents a non-breaking space. It prevents line breaks between words and preserves multiple spaces (browsers normally collapse consecutive spaces into one). Use it for: keeping phone numbers together (555 123 4567), preventing breaks between values and units (100 km), or forcing visible spaces in your layout.