HTML Comments

You can put comments between any tags in your HTML documents. Comments are not displayed by the browser, but they can help document your HTML. There is an exclamation point (!) in the opening tag, but not in the closing tag.

images/articles/html/html-comments.webp

Comments can still be seen in the source code for the document, but it is not shown onscreen. HTML comments are visible by the world and should never be used to store any information considered privileged or private.

1. Syntax

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

<!-- Your comment here -->

2. Uses of Comments

It is good practice to comment your code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code.

With comments you can place notifications and reminders in your HTML code. Comments are also great for debugging HTML, because you can comment out HTML lines of code, one at a time, to search for errors.