HTML Comments


HTML comments are used to make document note, or remove a piece of code. Comments are not displayed. Following is an example of a comment.

<!-- this is a single line comment -->
<!-- this is a
comment -->

Comment HTML code

To comment out piece of HTML code from the web page enclose it inside the comment tag.

<p>This is a sample paragraph.</p>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>


This is a sample paragraph.


This is a paragraph.


This is another paragraph.

Conditional comment

This works only for Internet Explorer on Windows and is used to set conditional instruction. Following is an example.

<!--[if lt IE 9]>
  <script src=""></script>
  <script src=""></script>

If IE version is less than 9 then HTML inside the comment will be used else ignored.

Script comment

We can also comment out script using the comment tag. This helps older browser to render the page properly. If the browser does not support JavaScript then the script code is ignored because of the comment.

<p>Simple Line</p>
  document.write("Hello World!");
<p>Simple Line</p>

Style comment

We can also comment out style using the comment tag.

        #container {
          color: #lightblue;