Tutorials Tonight's Logo

HTML COMMENT


HTML comment is used to make a comment in an HTML document.

HTML comment is ignored by the browser. Anything written as a comment is not taken under consideration.

Anything written in between <!-- and --> is considered a comment.

Example:

<!-- This is comment and it ignored by browser -->
<p>This is a paragraph.</p>
▶ Run the code

Use of comment

In large HTML documents it is good to use comments for future convenience.

<!-- Content starts -->
<p>In long and complex HTML document you can add comments like this.</p>
<!-- Content ends -->
▶ Run the code

Correct way to add comment

There are something that we need to take care while creating comment:

  • Comments should not be nested inside any other comment.
  • There should not be two continuous dash like --.
  • There should be no gap in dash(-) and exclamation mark(!).


<p>Comment is valid.</p>
<!-- This is a valid comment -->
▶ Run the code

<p>This Comment is invalid.</p>
<! -- This is a invalid comment -->
▶ Run the code

Multiline comment in HTML

Multiline comments span multiple lines where the line starts with <-- and ends with -->.

<p>Learning muliline comment.</p>
<!-- This is a comment line 1 
    This is a comment line 2
    This is a comment line 3-->
▶ Run the code
HTML Comment

Follow Us

Copyright © Tutorials Tonight. All Rights Are Reserved.