HTML Comment Tag
In this tutorial, we will learn about comment tag in HTML with the help of examples.
Comment Tag
HTML comment tag is used to insert comments in the HTML documents.
Comments are a piece of code that is ignored by the browser, but they can help document your HTML source code.
It is a good practice to add comments into your HTML code, especially in long and complex documents, to indicate sections of documents.
- You can add one or more comments to your HTML document.
- Comments are represented by <!–– ––>.
- It is a good practice of coding to add comments to your HTML source code.
- Comments help the coder and other people to understand the Source code of the document.
- The comment tag is useful during the debugging of codes.
- Browsers automatically ignore comments, but they can help document your HTML source code.
Types of Comment
There are two types of comments in HTML
- Single-line Comment
- Multi-line Comment
Single-line Comment
Single-line Comments are use to comment in one line only.
Syntax
<!--This is the syntax of Single-line comment-->
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML comments</title>
</head>
<body>
<!--This is a comment-->
<p>This is a simple text</p>
</body>
</html>
Output
<!--This is a comment-->This is a simple text
Multi-line Comment
Multi-line Comments are use to comment in more that one line.
Syntax
<!--This is the
syntax of
Multi-line comment-->
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML comments</title>
</head>
<body>
<!--This is a comment
<p>This is a first paragraph</p>-->
<p>This is a second paragraph.</p>
</body>
</html>
Output
<!--This is a commentThis is a first paragraph
-->This is a second paragraph.
Next Tutorial
We hope that this tutorial helped you develop better understanding of the concept of Comment tag in HTML.
Keep Learning : )
In the next tutorial, you'll learn about HTML <!DOCTYPE>
Tag.