HTML Comments

You can puts into comments into HTML pages to describe the page itself or to provide some kind of indication of the status of the page. Some source code control programs store the page status in comments, for example.



Text in comments is ignored when the HTML file is parsed; comments never show up onscreen - that's why they are comments. Comments look like the following:


<!-- This is a comment -->

Comments Types

  • Single-Line Comments
  • Multi-Line Comments

👉Single-Line Comments

Example:

<!DOCTYPE html>
<html>
<head> <!-- header start -->
<title> HTML Single-Line Comments </title>
</head> <!-- header close -->
<body> <!-- body section start here -->
<h1> What is Comments? </h1>
<p>Comment is a piece of code which is ignored by any web browser. It is a good practice to add comments to indicate sections of a document, and other notes to anyone looking at the code. 
</p>
<!-- Comments help you and others understand your code and increases code readability. -->
<body> <-- body section closed here -->
</html>

👉Multi-Line Comments

Example:

<!DOCTYPE html>
<html>
<head>
<title> HTML Multi-Line Comments </title>
</head>
<body>
<h1> What is Comments? </h1>
<-- Comments Never Show up Onscreen - that's why they're comments.
As you can see from, users can view your comments using the View Source functionality in their browsers, so don't put anything in comments that you don't want them to see.
-->
<p> Comment is a piece of code which is ignored by any web browser. It is a good practice to add comments to indicate sections of a document, and other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.
</p>
</body>
</html>

NOTES.....

You can enclose HTML tags within comments, and the browser will not display them. In fact, it's common to use comments to temporarily hide sections of a page, especially when testing things. Programmers generally refer to this as "commenting it out".
Previous Post Next Post