HTML-Comments

Comment tags are used to insert comments in the HTML source code. HTML comments are placed in between <!-- ... --> tags. So, any content placed with-in <!-- ... --> tags will be treated as comment and will be completely ignored by the browser. HTML comments are visible to anyone that views the page source code, but are not rendered when the HTML document is rendered by a browser.

Example :-

Comment Tag used to insert comment in the HTML

Result :-

HTML Comment Example

Valid And Invalid Comments

A comment can not be put inside the another comment tag . Second the double-dash sequence "--" may not appear inside a comment except as part of the closing --> tag. You must also make sure that there are no spaces in the start-of comment string.

Example :-

Here, the given comment is a valid comment

Result :-

HTML valid Comment Example

But, following line is not a valid comment and will be displayed by the browser. This is because there is a space between the left angle bracket and the exclamation mark.

Result :-
This is invalid Comment

HTML Comments Example

Multiline Comments

So far we have seen single line comments, but HTML supports multi-line comments as well.

You can comment multiple lines by the special beginning tag <!-- and ending tag --> placed before the first line and end of the last line as shown in the given example below.

Example :-

Result :-

This is multilene comment

Comment Tag

There are few browsers that support <comment> tag to comment a part of HTML code.

Note :-

The <comment> tag deprecated in HTML5. Do not use this element.

Result :-

This is Comment Tag