Comments in HTML – Guide with Examples

Himmat Kumar Apr 10, 2025, 4:49 PM
HTML
Views 840
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.

Comments

Please login to leave a comment.

No comments yet.

Related Posts

getting-started-with-html-setup-edit-run-code-in-browser
360 viewsHTML
Himmat Kumar β€’ Jul 25, 2024, 1:09 PM

Getting Started with HTML: Setup, Edit, and Run Your Co...

html-superscript-subscript-guide
945 viewsHTML
Himmat Regar β€’ Jun 9, 2025, 5:02 PM

Mastering Superscript & Subscript in HTML: A Complete H...

html-attributes-guide
231 viewsHTML
Himmat Kumar β€’ Aug 18, 2024, 10:58 PM

Understanding HTML Attributes: A Beginner's Guide

html-images-responsive-media-guide
1193 viewsHTML
Himmat Regar β€’ Jun 2, 2025, 6:46 PM

Images & Responsive Media in HTML – Formats, <picture>,...

hyperlinks-and-media-embedding-2025
568 viewsHTML
Himmat Regar β€’ Jun 23, 2025, 4:37 PM

Hyperlinks & Media: Embedding Content the Right Way in ...

html-seo-faq-2025
521 viewsHTML
Himmat Regar β€’ Jun 23, 2025, 4:41 PM

HTML & SEO FAQ 2025: Answers to the Web’s Most-Asked Qu...

html-css-js-online-compiler
380 viewsHTML
Himmat Regar β€’ May 30, 2025, 6:54 AM

HTML CSS JS Online Compiler – Best Free Tools to Code a...

what-is-html-full-explanation
486 viewsHTML
Himmat Kumar β€’ Oct 13, 2023, 11:40 PM

What is HTML? Full Explanation and Guide

html-tags
455 viewsHTML
Himmat Kumar β€’ Oct 19, 2023, 2:45 AM

HTML Tags

understanding-html-elements
238 viewsHTML
Himmat Kumar β€’ Jul 25, 2024, 1:09 PM

Understanding HTML Elements