About HTML Entities
HTML entities are special characters that are used in HTML to represent characters that might otherwise be interpreted as HTML code. They allow you to display reserved characters, which would otherwise be interpreted as HTML code, and invisible characters like non-breaking spaces.
Common Uses of HTML Entities
- Displaying reserved characters like <, >, &
- Adding special characters like copyright (©) or trademark (™)
- Including characters from different languages or writing systems
- Adding mathematical symbols or technical notations
- Ensuring consistent rendering across different browsers and platforms
How HTML Entities Work
HTML entities can be referenced in two ways:
- Named entities: Begin with an ampersand and end with a semicolon (e.g.,
<
for <) - Numeric entities: Use decimal or hexadecimal values (e.g.,
<
or<
for <) - HTML5 supports many named entities for common characters
- All Unicode characters can be represented using numeric entities
- Encoders and decoders help convert between plain text and HTML entity formats
Common HTML Entities
Some of the most commonly used HTML entities include:
<
= < (less than)>
= > (greater than)&
= & (ampersand)"
= " (quotation mark)'
= ' (apostrophe)
= non-breaking space©
= © (copyright)®
= ® (registered trademark)
Security Considerations
Proper use of HTML entities is important for web security. By encoding special characters, you can prevent certain types of cross-site scripting (XSS) attacks. Always encode dynamic content that might include user-supplied data to ensure it's rendered safely in HTML.
Examples
Plain Text | HTML Entities |
---|---|
<div> | <div> |
AT&T | AT&T |
5 > 3 | 5 > 3 |