HTML Comments

HTML Comments:

Comments are expressions or reactions about something given by someone or general audience.

HTML Comments are used for explaining the behaviour or the progress of a task or a process written by other users for better understanding.

HTML Comments are not visible in the browser screen but are defined in the HTML source code for reference. Adding comments is considered as a good practice in HTML source code.

HTML comments are placed in-between < !-- ..... --> tags. Any content placed within < !-- ..... --> tags will be considered as comment and will be completely ignored by the browser.

Invalid Comments:

Comments mustn’t be nested specified a comment cannot be placed within another comment. The double-dash sequence "--" should not appear inside a comment however enclosed as a part of the closing --> tag. There should not be any spaces in the starting comment string.

There are many types of HTML comments

  • Single Line Comment
  • Multiple Line Comment
  • Using Comment tag

Single Line Comment:

Single line comment are added by the special beginning tag <!-- and ending tag → placed before and end of the first line.


< !-- This is single line comment -->

Multiple Line Comments:

Multiple line comments are added by the special beginning tag <!-- and ending tag --> placed before the first line and end of the last line.


                    This is a multiline comment and it can
                span through as many lines you like.

Using Comment tag:

Few browsers allows tag but the tag is deprecated in HTML5.


                    <p>This is <comment>not</comment> using comment tag.</p>

Example :

<html> <body> <p> Knowledge2life is best learning website. </p> <!-- This is a comment --> </body> </html>


Knowledge2life is best learning website.