HTML Comments - How do I Select Thee, Let Me Count the Ways - HTML With Style | WebReference

HTML Comments - How do I Select Thee, Let Me Count the Ways - HTML With Style

Front Page1234567

HTML Comments

Those of you who have ever learned a programming language should be familiar with the concept of comments. Comments are used in the source of a program (or, in this case, in the HTML source of a Web page) to insert information for the benefit of someone examining the source, and have no impact on the meaning of the source. The uses for comments are many: you can use a comment to insert a reminder for yourself when you read the HTML source, or you can use one to explain the use of HTML at a certain point for someone else reading the source. You can also put a part of your document inside a comment so it is ignored if you want to disable that part without actually deleting it from the document.

Comment syntax in HTML is borrowed directly from SGML. To put things simply, a comment starts with the sequence of characters less-than, exclamation mark, dash, dash (<!--) and ends with the sequence dash, dash, greater-than (-->). Everything between these two delimiters is ignored. Here's an example of a comment:

<!-- This is a comment -->

The <! sequence might remind you of a Document Type Declaration, and like a Declaration, a comment may look like a tag, but it's not. It's just a comment. The only thing you can't have inside an HTML comment is a sequence of two dashes, as the following example illstrates:

<!-- This is a legal comment. -->
<!-- This, however -- is NOT a legal comment because
it contains two consecutive dashes. -->

The following is a comment containing markup, which is ignored:

<H1>A Heading</H1>
<P>A Paragraph with some
text and even perhaps, if
the mood beckons, a <a
and some <em>phrase markup</em>.

Remember that comments have no bearing on the function of an HTML document. As far as any program processing the source is concerned, they don't exist. They are there for human consumption only, and can help you when you edit your documents so that you don't have to stop and wonder why you did this or that in the source when you come back and examine it. Contrary to the case with most programming languages, however, it is not a good idea to litter your HTML documents with comments, since they will make your documents larger, which means they will take longer to download over a network.

Front Page1234567

Produced by Stephanos Piperoglou

All Rights Reserved. Legal Notices.

Created: September 24, 1998
Revised: September 24, 1998