the Source Web Publishing, an Industrial Strength List for Web Professionals

[Source Index] | [Feedback]
 

<!--...-->
(the Comment Tag)


Uses:

1.Allows the insertion of notes into the source document that will not be displayed by the HTML client.

2.Allows for the hiding of cetrain features by browsers that don't support those features (most notably to hide Scripting from browsers that don't support a particular scripting language.

Examples:

1. <!--This is a comment-->

2. <SCRIPT Language="YaddaScript">
<!--
[script type stuff goes here]
[this is inside a comment tag
to hide it from browsers that
don't support YaddaScript]
-->
</SCRIPT>

Notes:

Comments are often very useful in situations where many people will be editing the document, or in situations where the author wishes to make notes for future reference.

In long, complicated docments, placing comments at the beginning of blocks that need to be changed often can be used to make these blocks easier to find.

Keeping a history of what was changed, by whom, and when is a helpful practice when dealing with many documents that require different types of updating. This is most efficiently done by including that revision history in comments near the top of the document.

Comments are loaded with the file and add to the file's overall size. Keep this in mind when commenting. Every thousand characters (approximately) adds another kilobyte of data.

There is another usage for text stored in comments, influencing search engines. Some search engines will index words hidden in comments (and thus assign a higher relevance to certain pages during in response to certain queries). This practice is no longer effective on its own. In fact, the major search engines has developed filters to catch such 'keyword stuffing' and will penalize sites that abuse comments in this way.

Behavior:

According to SGML comment syntax rules, a comment element starts with <!, followed by zero or more comments, followed by >. A comment starts and ends with "--", and does not contain any occurrence of "--".

This means that these are also legal SGML comments:

  1. <!--------Comment-------->
  2. <!------Comment-->
  3. <!>

While example 3 is a waste of typing, it's still a legal comment.

Getting tricky with your comments can possibly lead to large sections of your document not showing up due to the number of hyphens telling the browser that the comment is not finished.

To make it easier on yourself (some clients aren't very good with parsing strict HTML much less SGML), always think of an HTML comment beginning with <!--, ending with --> and not containing any extra --'s or >'s anywhere in the comment.

New Uses:

You may find other instances of the <! beginning that would seem to suggest that which follows is a comment.

  1. <!DOCTYPE...> is not a comment but a document type identifier.
  2. <!--#...--> is a special type of comment used for server side includes.
  3. <!--// is a special type of comment used with the SCRIPT element that nests a JavaScript comment inside the usual script-hiding comment.

Top | Index


Site Hosted by GEOCITIES--Athens Neighborhood
http://geocities.datacellar.net/Athens/2603/comment.html
© 1997, MoonBoots Enterprises
maintained by MRC
last modified 1998.03.12
send comments to moonboots@earthling.net
1