HTML entities are special characters or symbols that can be inserted into HTML documents using a code or string of characters that represent that specific entity. For example, the entity for the copyright symbol is ©. When the browser reads this code it will display the copyright symbol rather than the string of characters.
Examples: ©, >, <, &, (non-breaking space), etc.
How to use HTML entities
HTML entities can be used in HTML documents by including the entity code within the HTML code.
For example, to insert a copyright symbol in an HTML document, you would include the following code:
<p>Copyright © 2022 My Website</p>
This would display the text "Copyright © 2022 My Website" in the browser.
You can also use HTML entities in HTML attributes such as the alt attribute of an image.
For example:
<img src="example.jpg" alt="Example ©">
It's important to note that some HTML entities have a corresponding Unicode character that can be used instead.
For example, instead of using the entity code ©, you can use the Unicode character ©. However, using the entity code is more reliable as it will work with older browsers that do not support Unicode characters.
Some commonly used HTML entities
Here is a list of some commonly used HTML entities, their entity name, entity number, and a brief description:
- (non-breaking space) - This entity is used to create a non-breaking space in HTML, which will prevent text from wrapping to the next line. It can be used to add extra spacing between words or characters.
- < (less than) - This entity is used to insert the less than symbol < in HTML.
- > (greater than) - This entity is used to insert the greater than symbol > in HTML.
- & (ampersand) - This entity is used to insert the ampersand symbol & in HTML. It is often used in URLs and query strings.
- © (copyright) - This entity is used to insert the copyright symbol © in HTML.
- ® (registered trademark) - This entity is used to insert the registered trademark symbol ® in HTML.
- € (euro) - This entity is used to insert the euro symbol € in HTML.
- ¥ (yen) - This entity is used to insert the yen symbol ¥ in HTML.
- £ (pound) - This entity is used to insert the pound symbol £ in HTML.
- — (em dash) - This entity is used to insert an em dash — in HTML.
- “ (left double quote) - This entity is used to insert a left double quotation mark “ in HTML.
- ” (right double quote) - This entity is used to insert a right double quotation mark ” in HTML.
This is just a small sample of the many different HTML entities available. It's worth noting that there are many other entities available for different languages, mathematical symbols, and special characters.