Dan's Web Tips:HTML Comments[<== Previous] | [Up] | [Next ==>] See also Swedish translation (done by others in their own site)
TIP: When you put comments in your HTML code, begin
the comment with Many people who attempt to put comments into their HTML code -- text intended for the reference of the developer but not to be displayed by the browser -- get the syntax wrong, which can cause some browsers to mistakenly display part of the comment, or even worse, consider big chunks of the rest of the document to be a comment and ignore them. This widespread confusion about comment syntax is understandable given that HTML comment syntax is a rather inscrutable outgrowth of SGML (Standard Generalized Markup Language), a language devised for the formatting of government documents which formed the basis of HTML. Maybe some of the same people who devised the 1040 tax forms also created the syntax rules for SGML, and hence HTML.
While the popular conception is that comments open with
But since you don't want to have to be so careful in counting your pairs
of dashes, it's better not to include any double dashes anywhere in a
comment line, so you can be sure the proper syntax is followed. This
can get to be a bit of a problem in commenting out JavaScript code
(recommended to hide it from older browsers), since "--" is frequently
encountered as a decrement operator. You'll have to use your best judgment
in such cases about whether to rewrite your JavaScript code to avoid this
operator, or live with a malformed "comment" that probably won't crash
the common browsers which are used to dealing with such bad syntax anyway.
Just try not to use comments like Another character that you should avoid within comments is the greater-than symbol (>). While this is legal within a comment, some browsers don't parse comments correctly, and they might think that a greater than sign is the end of the comment. So avoid it, though this may pose a problem both in JavaScript code and when you're "commenting out" some HTML markup you're temporarily removing from your page.
Another flawed syntax sometimes used is If you use any automated program to generate HTML code, such as a WYSIWYG editor or a program that generates HTML from a spreadsheet or database, watch out for malformed comments these programs may insert; unfortunately, the authors of such software sometimes get the comment syntax wrong and inflict this on all their users.
NOTE: One of the many ways HTML 5.0 "dumbs down" the standards
is that it has dropped all attempts to comply with SGML rules, and instead
adopts simplified comment syntax rules that don't include many of these
complexities; comments are simply delimited by Links
[<== Previous] | [Up] | [Next ==>]
This page was first created 04 Aug 1997, and was last modified 06 Apr 2002.
|