In HTML, reserved characters must be replaced with character entities. We can also replace some characters that are not present on our keyboard with the help of entities.
Some characters like less than (<) or greater than (>) signs are reserved in HTML. If you use these signs in your text, the browser might mix them with tags. Therefore we use character entities to display reserved characters in an HTML document.
In an example below this is how character entity looks like:
&entity_name ; or &#entity_number ;
It’s better to use entity number instead of entity name, because browsers do not support all entity names.
Note:- Don’t forget to add semicolon at the end of entity name or number.
How to use an entity in an HTML
In an example below let’s see how you can use entity name and number in HTML:
<!DOCTYPE html> <html> <body> <h2> HTML Entity Example </h2> <!--by name --> <p> This is a less than sign: < </p> <!-- by number --> <p> This is also a less than sign : < </p> </body> </html>
Some Commonly Used HTML Character Entities
|Description||Entity Name||Entity Number||Result|
|Single quotation mark||'||'||‘|
|Double quotation mark||"||"||“|
|non-breaking space|| ||&160;|