Add Comments to Your HTML Document


Although the first HTML pages you write will be fairly simple, they can get complicated in a hurry. As your pages become more detailed and complex, you might find it difficult to remember what a particular section of code is supposed to do. The easiest solution is to add comments to your HTML source code. Comments function as little notes to yourself (see Figure 1-4). Web browsers will ignore the comments completely, but they will come in very handy if you are writing a complex page with many lines of HTML.

click to expand
Figure 1-4: HTML code with a comment added.

Adding comments to your HTML is easy. Just enclose your comment between comment tags: <!-- Add your comment here -->.

To add a comment to the Web page you just created, follow these steps:

  1. Open index.htm in Notepad.

  2. Anywhere between the <body> </body> tags, type the first comment tag: <!-- (a “less than” sign, followed by an exclamation point and two dashes).

  3. Type This is a comment.

  4. Type the closing comment tag: --> (two dashes followed by a “greater than” sign).

  5. Your completed comment should look like this:

    <!-- This is a comment -->

If you save and display the page in a browser, and you have entered the comment tags correctly, the comment should not display. If you see it, check your comment tags to make sure you wrote them correctly.

Tip

Comment tags are useful for more than putting little notes in your code. When you want to use JavaScript to add some special effects to your page, you can hide the script in comment tags to hide it from older browsers that can’t use JavaScript. Older browsers then will ignore your script, whereas JavaScript-enabled browsers will execute it. To learn more about using JavaScript in your pages, read Chapter 15.




How to Do Everything with HTML & XHTML
How to Do Everything with HTML & XHTML
ISBN: 0072231297
EAN: 2147483647
Year: 2003
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net