HTML Tutorials for Beginners to Advance

HTML Basic Structure, Elements in HTML, HTML Headlines, List in HTML, Insert Images in Web Pages, Tables in HTML, HTML form design, HTML5 Elements, HTML Canvas, etc.

HTML Comments


Comment tags are used to insert comments in the HTML source code.

Comment is a piece of code which is ignored by any web browser. It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.

HTML comments are placed in between <!-- ... --> tags. So any content placed with-in <!-- ... --> tags will be treated as comment and will be completely ignored by the browser.


HTML Comment Tags

You can add comments to your HTML source by using the following syntax:

See this example:

<!-- Write your comments here -->

Output:

<!-- Write your comments here -->


Notice that there is an exclamation point (!) in the opening tag, but not in the closing tag.

Note: Comments are not displayed by the browser, but they can help document your HTML source code.

With comments you can place notifications and reminders in your HTML:

See this example:

<!-- This is a comment -->

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

<!-- Remember to add more information here -->

Output:

<!-- This is a comment -->

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

<!-- Remember to add more information here -->

Comments are also great for debugging HTML, because you can comment out HTML lines of code, one at a time, to search for errors:

See this example:

<!-- Do not display this at the moment
<img border="0" src="pic_mountain.jpg" alt="Mountain">
-->

Output:

<!-- Do not display this at the moment
<img border="0" src="pic_mountain.jpg" alt="Mountain">
-->

Conditional Comments

You might stumble upon conditional comments in HTML:

See this example:

<!--[if IE 9]>
    .... some HTML here ....
<![endif]-->

Output:

<!--[if IE 9]>
    .... some HTML here ....
<![endif]-->

Conditional comments defines some HTML tags to be executed by Internet Explorer only.