close
The Wayback Machine - https://web.archive.org/web/20240118164859/https://www.geeksforgeeks.org/html-comments/
Open In App
Related Articles

HTML Comments

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

HTML Comments are used to insert comments in the HTML code. It is a good practice of coding so that the coder and the reader can get help to understand the code. It is a simple piece of code that is wiped off (ignored) by web browsers i.e., not displayed by the browser.

Comment Types

There are three types of comments in HTML which are:

We will explore different types of Comments with suitable examples.

Single-line Comment

 The single-line comment is given inside the ( <!–  comment –> ) tag. 

Syntax

 <!--  comment -->

Example: In this example, we will see the implementation of the above approach.

HTML




<!DOCTYPE html>
<html>
 
<body>
    <!--This is heading Tag, It wont be displayed by the browser -->
    <h1>GeeksforGeeks</h1>
 
    <!--This is single line comment,It wont be displayed by the browser -->
    <h2>This is single line comment</h2>
 
</body>
 
</html>


Output:

_com1

Multi-line Comment

Multiple lines can be given by the syntax (<!– –>), Basically it’s the same as we used in single line comment, difference is half part of the comment (” –> “), is appended where the intended comment line ends. 

Syntax

 <!--  Multi
Line
Comment -->

Example: In this example, we will see the implementation of above approach.

HTML




<!DOCTYPE html>
<html>
 
<body>
 
    <!-- This is
         heading tag -->
    <h1>GeeksforGeeks</h1>
 
    <!-- This is
         multi-line
         comment -->
    <h2>This is multi-line comment</h2>
 
</body>
 
</html>


Output: 

_com3

Using comment tag

There used to be an HTML <comment> tag, but currently it is not supported by any modern browser.

Syntax

 <comment> Some Comment </comment>

Example: In this example, we will see the implementation of above approach.

HTML




<!DOCTYPE html>
<html>
 
<body>
    <comment>This is heading tag</comment>
    <h1>GeeksforGeeks</h1>
    <comment>This is multi-line
        comment
    </comment>
    <h2>This is a comment using</h2>
 
</body>
 
</html>


Output:

BERJAYA


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 13 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials