Making HTML Comments

Putting comments in HTML code is considered good coding practice in today's standards. Think of comments as post-its notes designed to remind you what a particular block of HTML code is all about. Comments aren't part of the main executable HTML code, therefore it is written in such a way that it would be ignored by the browser during rendering. To see how comments are incorporated in HTML code, see the example below:

1<!DOCTYPE html>

2<html>

3<head>

4<title>Learning How To Put Comments in HTML</title>

5</head>

6<body>

7<!—This is an example of a comment—>

8<p> A comments is written just above this paragraph tag</p>

9<!—The next code makes an ordered list—>

10<ol>

11<li>Notice another comment above the ordered list tag</li>

12<li>I think that's all for making comments in HTML</li>

13</ol>

14</body>

15</html>

Looking at our example above, line 7 and line 9 showcases comments made in an HTML code. Saving this HTML code in an .html file and opening it in your browser would reveal that during rendering, the comments are completely ignore by the browser and therefore wasn't displayed in the output. As what we have previously mentioned, a comment's job is to remind HTML programmers what a particular block or line of code is all about.

Also know that comments are also a type of tag. In order for a line of text to be recognized as a comment and not a paragraph, it must be enclosed within the opening comment tag and the closing comment tag. The opening comment tag is written as <!—and the closing comment tag is written as—> .  Look at lines 7 and 9 of our example code to see an example of this.