HTML

Comments in HTML – Guide with Examples

Apr 30, 2025, 6:06 AM
Blog Thumbnail

In this lesson, we will look at comments in HTML with the help of example code which uses it to mark important notes for developers or improve code legibility. It assists in organizing the code easier.

πŸ“˜ Comments for HTML

Comments in HTML are stored between the tags <!-- and -->. People often forget about documentation, however, in comments you can write anything. Comments don’t get stored in the actual display of the website, however, they do assist in storing relevant information for viewers of the source code.

πŸ”– Tag for Comments in HTML

There are standard conventions you need to follow if you want to put comments in your HTML document. You can use the following code:

      <!-- Type your comments here -->
    

It is to be noted that there is an exclamation mark in both the start and end tag.

In any case, however, comments are of no use in programming. Wrappers of tags assist you in displaying without any issue during website view.

✍️ Add Comments

Adding HTML comments allows you to place notifications and reminders in your code and to explain the various sections featured in it.

Example:

      <!-- This is a comment -->
<p>This is a paragraph.</p>

Output:

This is a paragraph.

πŸ™ˆ Hide Content

You can also use comments to hide content. This technique can be useful when you need to hide content temporarily.

Example:

      <p>This is a paragraph.</p>
<!-- <p>This is another paragraph</p> -->
<p>This is a paragraph too.</p>

Output:

This is a paragraph.

This is a paragraph too.

With the use of comments, you can hide more than one line. Everything that appears between the opening comment symbol will not be displayed.

Example: Hide a section of HTML code

      <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>

Output:

This is a paragraph.

This is a paragraph too.