Commenting Your HTML Code

The comment tag is used to insert a comment in the source code. Comments within your source code can be used to explain your code which may help you with editing at a later date. The comment code will be ignored by the browser. When you put comments in your HTML code, begin the comment with <!--, end it with -->, and avoid using double hyphens -- or the greater-than symbol  > within it the comments. You should avoid putting two or more adjacent hyphens inside comments.


<!--Masthead Start -->

Masthead graphic and content would go between these tags

<!-- Masthead End-->

<!-- Navigation Start -->

The Site Navigation would go between these tags

<!-- Navigation End-->

<!-- Site Search Start -->

The Site Search box would go between these tags

<!-- Site Search End-->

<!-- Content Start -->

All content would go between these tags

<!-- Content End-->

<!-- Footer Start -->

All footer information would go between these tags

<!-- Footer End-->

Program Specific Comments

Program-specific information can be stored within comments. In this case they will NOT be visible for the user, but they are still available to the program. Comments tags are also generated by various WYSIWYG software programs such as FrontPage and Expression Web. Those comments tags may initiate some form of server side scripting language. For example, the FrontPage <!--webbot bot--> tags which are wrapped inside HTML comments.


<!--webbot bot="Include" u-include="_includes/new-credits.htm" tag="BODY" -->

<!-- #BeginEditable "doctitle" -->

<title>House of Oak &amp; Sofas</title>

<!-- #EndEditable -->

<!-- #BeginEditable "scripting" -->

<script src="scripts/gen_email.js" type="text/javascript"></script>

<!-- #EndEditable -->

Commenting Scripts and Styles

It is also good practice is to comment the text inside the script and style elements to prevent older browsers, that do not support scripting or styles, from showing it as plain text.


<!-- document.write("Hello World!") //-->


Your comments can span multiple lines as in:

<!-- This comment spans

multiple lines making

the code easy to read

after a few months. -->

Conditional Comments

Conditional comments work only with Internet Explorer for Windows and are used to give special instructions to Internet Explorer. They work with IE5 and up.

<!--[if IE 6]>
Special instructions for IE 6 here

There structure is the same as a html comment (<!-- -->). so other browsers will see them as normal comments and will ignore them. Internet Explorer has been programmed to recognize the special <!--[if IE]> syntax, resolves the if and parses the content of the conditional comment as if it were normal page content.

Google conditional comments and you will find many examples.