The Wayback Machine - https://web.archive.org/web/20240619164806/https://www.geeksforgeeks.org/html-comments/
Open In App

HTML Comments

Last Updated : 22 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

HTML comments are an very important for developers, providing a way to annotate code without affecting the rendered webpage. HTML Comments enhance code readability, facilitate collaboration, and can be used to temporarily disable code segments. Enclosed within <!– and –>, HTML comments serve as invisible notes within the code.

What are HTML Comments?

HTML comments are enclosed within <!– and –>, and serve to annotate code for developers. They provide explanations, reminders, or instructions that are invisible on the rendered webpage. These comments aid collaboration and enhance code readability, offering insights into the code structure and purpose.

Ways to Comment in HTML

There are two ways to comment in HTML. Each type of comment can be used to add comments in HTML.

Comment

Descriptions

Syntax

Single-line

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

<!–  comment –>

Multi-line

It follows the syntax of a single-line comment by adding multiple lines in the comment.

<!– Multi
Line 
Comment –>

Note: The shortcut for adding the comment through the keyboard is by typing Ctrl + / in Windows, and Command + / for Mac users.

HTML Comments Example

  • Single Line Comment in HTML
  • Multiline Comment in HTML

Example 1: This HTML code shows how to write single-line comments and how to write an inline comment in HTML.

HTML
<!DOCTYPE html>
<html>

<body>
    <!--This is heading Tag-->
    <h1>GeeksforGeeks</h1>

    <!--This is single line comment-->
    <h2>This is <!--given for--> single line comment</h2>

</body>

</html>

Output: None of the comment will render on the browsers.

HTML-Comments-single-line-comment

HTML Comments Example Output

Example 2: The following HTML code shows how to write multi-line comments and how to write hidden HTML code sections.

HTML
<!DOCTYPE html>
<html>

<body>

    <!-- This is 
         heading tag -->
    <h1>GeeksforGeeks</h1>

    <!-- This is
         multi-line
         comment -->
    <h2>This is multi-line comment</h2>
    <!-- <button style="font-family: Sans-serif;">
           Click Me
         </button> -->

</body>

</html>

Output: None of the comment will render on the browsers.

HTML-Comments-multi-line

HTML Comments Example Output

Conclusion

HTML comments play a important role in facilitating communication within code, aiding collaboration among developers. They serve as reminder notes and enhance project documentation. Invisible on the front end, they maintain code clarity. Understanding HTML comments and their usage is essential for developers, promoting well-documented projects.


Previous Article
Next Article

Similar Reads

How to write comments in HTML ?
In this article, we have to pass a comment for an HTML by using &lt;!-- Comment --&gt; tag. In html, we can add single-line comments and multi-line comments. These are used to insert comments in the HTML code. It is helpful to understand complex code. The comment tag is useful during the debugging of the codes. Syntax: Single line comment &lt;!-- C
1 min read
Design a Nested Chat Comments using HTML CSS and JavaScript
In this article, we will learn how to create Nested Comments using JavaScript. We must have seen it on social media like Facebook, Instagram, Youtube, Twitter, etc. We have seen the use of the nested comment in the comment section of these social sites. Approach: Create a folder nested-comments on your local machine and go to that folder.Create 3 f
2 min read
How to auto like all the comments on a facebook post using JavaScript ?
In this article, we are going to learn how to like all the comments on a Facebook post automatically. Many times we want to like all the comments of friends on our post or on any other's post, so this script helps us to save time and effort by automatically liking all the comments on the post. Approach: Make variable comments that points to an arra
2 min read
How to write comments in PHP ?
In this article, we have to pass a comment for PHP code by using some simple basic syntax. Comments are helpful to understand the complex code. The comment tag is useful during the debugging of the codes. We use comments to understand the functionality of the code. Basically, the single-line comments begin with // comments. Example 1: C/C++ Code
1 min read
SASS | Comments
Comments in SASS is very similar to the comments in any other programming language. But the difference comes when we talk about the type of comments will be there in the compiled CSS file. There are two types of comments in Sass: Silent Comments: Silent comments are single-line comments. When we compile Sass file these comments don't reflect in com
1 min read
How to block comments in YAML ?
YAML is a human-friendly data serialization standard for all programming languages. It is commonly used for configuration files and in applications where data is being stored or transmitted. The Normal Way for commenting in YAML is Inline commenting with the "#" symbol, however, if you want to comment blocks then we have a list of ways in which it
2 min read
YAML Comments
Comments are used to prevent the execution of statements. Comments are ignored while the compiler executes the code. Comments are user-friendly as user can get explanations of code using comments. Since you are alright with the sentence structure and fundamentals of YAML, let us continue further into its details. In this part, we will perceive how
3 min read
Integrating Facebook Comments Plugin in Django Project
Django is a Python-based web framework that allows you to quickly create efficient web applications. It is also called batteries included framework because Django provides built-in features for everything including Django Admin Interface, default database – SQLlite3, etc. In this article, we will learn to integrate the Facebook comment plugin in Dj
2 min read
Documentation Comments in JSDoc
In JSDoc we need to include documentation comments in the code through which JSDoc will generate an HTML documentation website. Let's see how to create documentation comments for different types of code. String, Numbers &amp; Arrays: C/C++ Code /** * Site Name * @type {string} */ const siteName = &quot;GeeksForGeeks&quot;; /** * Number * @type {num
4 min read
WordPress Delete Comments
WordPress is a tool and an open-source Content Management System that is totally based on PHP and MySql which is used to create a dynamic website. WordPress was written in PHP language by Matt Mullenweg. It is one of the most popular interfaces that allow users to customize and manage the website from its back-end content management system. To orga
2 min read