HTML comments are not displayed in the browser, but they can help document your HTML source code.
Comments are some text or code written in your code to give an explanation about the code, and not visible to the user. Comments which are used for HTML file are known as HTML comments. Anything written between these tags will be ignored by the browser, so comments will not be visible on the webpage.
Comments of any code make code easy to understand and increase readability of code.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Comments are not displayed in the browser -->
</body>
</html>
You can add comments to your HTML source by using the following syntax:
Example:
HTML
<!-- Write your comments here -->
With comments you can place notifications and reminders in your HTML code:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Comments are not displayed in the browser -->
</body>
</html>
Comments can be used to hide content.
This can be helpful if you hide content temporarily:
Example:
HTML
<!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>
You can also hide more than one line. Everything between the <!--
and the -->
will be hidden from the display.
Example:
HTML
<!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>
Comments can be used to hide parts in the middle of the HTML code.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>This <!-- great text --> is a paragraph.</p>
</body>
</html>