Html Comments

Although HTML comments are not visible in the browser, they can aid in the documentation of your HTML source code.

 

HTML Comment Tag

Use the following syntax to add comments to your HTML source:

<!-- Write your comments here -->


Notice that the start tag has an exclamation mark (!) while the end tag does not.
 

Add Comments

You can use comments to add notifications and reminders to your HTML code:
Example :

<!DOCTYPE html>
<html>
<body>
  	<!-- This is a comment -->

    <p>This is a paragraph.</p>

    <!-- Remember to add more information here -->
</body>
</html>

Try with example

Output :

 This is a paragraph.

 

Hide Content

Comments can be used to conceal information.

Which can be useful if you want to hide material for a while:

Example:

<!DOCTYPE html>
<html>
<body>
  	<p>This is a paragraph.</p>

<!-- <p>This is another paragraph </p> -->

<p>This is a paragraph too.</p>
</body>
</html>

Try with example

Output :

This is a paragraph.
This is a paragraph too.

 

You can even hide multiple lines at once; everything between them will be hidden from view.

Example:

<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
<!--
<p>Look at this cool image:</p>
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
<p>This is a paragraph too.</p>
</body>
</html>

Try with example

Output:

 This is a paragraph.
 This is a paragraph too.

Because you may comment out HTML lines of code one at a time to check for mistakes, comments are also useful for debugging HTML.

 

Hide Inline Content

Comments can be used to obscure parts of the HTML code that are in the middle.

Example :

<!DOCTYPE html>
<html>
<body>
<p>This <!-- great text --> is a paragraph.</p>
</body>
</html>

Try with example

Output :

This is a paragraph.