HTML Comments

HTML Comments

In HTML document comments are denoted by the special character strings . The first string is the start of the HTML comment and the second string is used to indicate the end of the comment. Anything that is written between these two strings is considered to be a comment.

The comments are not displayed by the browser even if they are written in the body of the HTML document. The string that is used to start the comment should not have spaces between its characters but this is not the mandatory condition for the ending comment.

Following is the example of comment:

<!- -This is a comment – ->

If this statement is written in the HTML document it will not be displayed by the browser.

Comments cannot be nested. If you want to use more comments, you should not span more than one line rather use comment strings to display the comment otherwise the comment without its string will be displayed on the browser.

Each comment is described as a text string that is surrounded by the characters string. We can also add empty comments as:

<! >

EXAMPLE:

Two or more comments can be used as follows:

<!- – This is a comment – –

– – this is the second comment that is declared with the first comment – ->

comment

This will not be shown on the browser:

shown-on-the-browser

Two or more comments cannot be declared using the following format:

<! – – this is a comment

This comment is not declared properly, the browser will display it. It should be avoided.

– – >

NOTE: Do not declare comments like this otherwise the browser may mishandle these sophisticated comments. Use simple structure for comments.