HTML Comment Tag

What is the HTML Comment Tag <!-- --> and why is it used?

The HTML Comment Tag <!-- --> is used to add a comment in the code section. It allows developers to write notes or explain what the code does or what it is for.

Developers also use this tag to temporarily hide elements while creating webpages.

In short, comments help make the code easy to understand and manage.

Syntax:

<!-- You type the comment text here. -->

Components of the Comment Tag:

<!-- This is a comment -->
↑ ↑ ↑
Opening Mark Comment Text Closing Mark

  1. Opening Mark: It is the first part of the comment tag and starts with <!--.
  2. Comment Text: It is the middle part where you write a comment about the code.
  3. Closing Mark: It is the last part of the comment tag and ends with -->.

Types of comments:


1. Single-Line Comment:
<!-- Text in one line about what you understand in your own words, which you write in the code. -->
2. Multi-Line Comment:
<!--
Text in multiple lines about what you understand in your own words,
which you write in the code.

-->

Example:

<!DOCTYPE html>
<html>
<head>
<title>Single-Line Comment</title>
</head>
<body>
<!-- This heading displays the main title of the webpage Tutorial Index. -->
<h1>Tutorial</h1>
<p>Welcome to my TutorialNest.com.</p>
<!--
This heading displays the main title
of the webpage Tutorial Index.
-->
<h1>Tutorial</h1>
<p>Welcome to my TutorialNest.com.</p>
</body>
</html>

ONLINE WEB TOOLS

WhatIsMyIpAddress
Shorterner
Web Services