Working with Character Entities
Some characters are reserved in HTML and we cannot use them as a regular character in the HTML, code. For example, it is not possible to use the less than (<) sign, as the browser will mix them with tags. Therefore, if you want the browser to display the reserved characters, then they must be replaced with character entities in the HTML code. A character entity has three parts: an ampersand (&), an entity name or # and an entity number, and a semicolon (;).
For example, if you want to insert the symbol of copyright on a Web page, then you need to provide its entity name as © or entity number as ©. Below given table briefly describes commonly used character entities:
Entity Name |
Description |
Result |
Entity Number |
---|---|---|---|
|
Non-breaking space |
|
  |
< |
Less than |
< |
< |
> |
Greater than |
> |
> |
& |
Ampersand |
& |
& |
" |
Quotation mark |
“ |
" |
¡ |
Inverted Exclamation Mark |
! |
¡ |
Let’s do the following steps to work with character entities:
<!DOCTYPE html>
<head>
<title>Character Entities</title>
</head>
<body>
<h4>Using Character Entities</h4>
<font size=”4”>
This Is an example of inserting spaces.
<p>This is the < (less than) sign.</p>
<p>This is the > (greater than) sign.</p>
<p>This is the & (ampersand) sign.</p>
<p>This is the " (quotation) mark.</p>
<p>This is the &lexcle; (Inverted Exclamation) mark.</p>
</font>
</body>
</html>
Save the document with the name CharacterEntities.html.
Note: Character entities are case-sensitive; therefore, they are always given in lower case.
Commenting the Text
A comment tag is used to hide the text from the Web page. Comments are written inside the opening and closing (<!..and ..>) tags, which hide any content between them from the Web browser. In this way, you can place code-specific information inside the comment tags. Comments are not visible to the user when the program is executed, but they are still available in the program.
Let’s do the following steps to comment the text:
<!DOCTYPE html>
<head>
<title>Commenting text</title>
</head>
<body>
<!--This is a comment, --->
<!—This comment will not be displayedïƒ
<p> This text will be displayed.
This is a normal text.
</p>
</body>
</html>
Save the document with the name CommentingText.html.