HTML comments are ignored by the browser while displaying your web pages. It is good practice to add comments to your complex documents to indicate the sections of a document. Comments help you and others to understand your code.
Comments are used to indicate what the following code does.
Syntax:
<!-- Write your comments Here -->
Comments start with opening tag <!- – and closing tag – ->. Any texts written in between the opening and closing tag are ignored by the browser.
Code:
<!DOCTYPE html>
<html>
<head>
<title>HTML Comments</title>
</head>
<body>
<!-- This is a comment.-->
<p> This is a paragraph.</p>
<!-- This is my second comments. -->
</body>
</html>
Output:
Inline Content Comments
Comments can be used to hide the parts of your content.
Syntax:
<p> Some Text ... <!-- Inline Comment Here --> Remaining Text. </p>
Example:
<!DOCTYPE html>
<html>
<head>
<title>HTML Comments</title>
</head>
<body>
<p>Comments help you and others to understand
your code.<!--Inline Comments --> Comments can be used to
hide the parts of your content.</p>
</body>
</html>
Output:
Multiline Comments:
We have seen single-line comments. But don’t get confused. The HTML supports multi-line comments as well.
Syntax:
<!-- Some Comment 1.
Some Comment 2,
Some Comment 3 etc -->
Code:
<!DOCTYPE html>
<html>
<head>
<title>HTML Multiline Comments</title>
</head>
<body>
<!-- Comments start Here,
but don't get confused
HTML supports multiline comments.
This is a multiline comments.-->
<p> Document content goes here</p>
</body>
</html>
Output:
You may be interested in the following topics: