HTML primer – HTML Comment Tags

HTML primer – HTML Comment Tags cover image
  1. Home
  2. HTML
  3. HTML primer – HTML Comment Tags

As your HTML pages grow, so will their complexity. Maintaining such complex pages can be quite a problem if there is no way to add documentation to these files. Fortunately, HTML provides tags through which you can add comments to various sections of your scripts. Take my advice, use the comments tags generously in your documents. When you look back at your files after a few months you shall be able to decipher the code much faster.

The starting comment tag is <!– (that’s the ‘lesser than’ sign followed by an exclamation mark and two dashes) and the ending tag is –>.

The browser does not display any text placed between these tags. Try this out yourself. Open a new document in Notepad and type the following and check the results in a browser.

<HTML>
<HEAD>
<TITLE>Testing Comment tags in HTMLs</TITLE>
</HEAD>
<BODY>
I am visible.
<!-- I am not displayed by the browser -->
</BODY>
</HTML>

Your comments can span multiple lines as in:

<!--
This comment 
spans multiple lines
making the code easy to read
after a few months.
-->

Comment tags are invaluable if you work (or are planning to work) in a group. Your colleagues will be able to understand and decipher your code faster if you have used comment tags judiciously.

HTML