Welcome Guest ( Log In | Register )




                Web Hosting Guide

Good Comments Make Good Html., Commenting makes HTML easier to write.
vujsa
post Feb 24 2005, 01:03 AM
Post #1


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714
myCENTs:35.43


Good Comments Make Good HTML.
Commenting makes HTML easier to write.

This is a spin off from another article I wrote entitle Good Comments Make Good Scripts. While the code is different, the concepts for comment are the same.
Enjoy!

Disclaimer!
This tutorial is intended to be used to show the benefites of commenting your HTML in order to write clean, easy to read code. For the purpose of this tutorial, HTML, XML, XHTML validating is not taken into consideration. While I will make an effort to point out non-standardized code, validation has never been my priority and I'll probably miss a few things. Always run your HTML through an HTML validater to check for compatability issues.


Reasons for commenting HTML:
    - Makes your code easier to trouble shoot.
    - Add a friendly reminder of things you wanted to include in your page.
    - Allows you to save information about the page without showing the general public.
    - Provides a way of giving yourself credit for creating a nice page.
    - Used as instructions for JavaScript and other client side script usage.

Getting Started!
-------------------------------------------------------------------
An HTML comment tag is quite simple, everything inside the tag is hidden from the browser and is considered to be the comment.
The HTML comment tag is:
CODE
<!-- -->


Example with a comment:
CODE
<!-- Here is a comment! -->


Example of a multi-line comment:
CODE
<!-- I would like take this oppurtunity to descript the color of the sky.
The color of the sky is a unique shade of the color blue.
Unless of course there is overcast and then its more like gray.
Then again in the fog evreything is white.
Appearently the sky is multicolored! -->


Now lets talk about when and where to comment yout HTML.

The first place I like to add a comment in a web page is at the beginning of a table.
Example:
CODE
<!-- Start table 1 here - 3 rows high and 4 columns wide -->
<TABLE BORDER="1">
<TR>
...


Another really good use for a comment in a table is when a cell spans multiple rows or columns.
Say that you have a table that is 4 rows and 4 columns and you want one really large cell in the middle.
Attachment:
Attached File  table.JPG ( 5.56K ) Number of downloads: 94

Comments will help you keep track of where cells used to be.
Example:
CODE
<!-- Table 1 - 4 rows high and 4 columns wide -->
<TABLE BORDER="1">
   <TR>
       <TD>
           Cell 1-1
       </TD>
       <TD>
           Cell 1-2
       </TD>
       <TD>
           Cell 1-3
       </TD>
       <TD>
           Cell 1-4
       </TD>
  </TR>
  <TR>
       <TD>
           Cell 2-1
       </TD>
       <TD COLSPAN="2" ROWSPAN="2">
           Cell 2-2
       </TD>
        <!-- Cell 2-3 would have been here -->
       <TD>
           Cell 2-3
       </TD>
   </TR>
   <TR>
      <TD>
           Cell 3-1
       </TD>
        <!-- Cell 3-2 would have been here -->
        <!-- Cell 3-3 would have been here -->
       <TD>
           Cell 3-4
       </TD>
   </TR>
   <TR>
      <TD>
           Cell 4-1
       </TD>
       <TD>
           Cell 4-2
       </TD>
       <TD>
           Cell 4-3
       </TD>
       <TD>
           Cell 4-4
       </TD>
  </TR>
</TABLE>
<!-- End table 1 here -->

I use this frequently as I tend to get confused when I start spanning cells.

Occasionally I have very lengthy forms that I need to comment in order to keep track of what's what.
Example:
CODE
........
<INPUT TYPE="TEXT" NAME="Var126" SIZE="25"> <!-- This is the 126th input variable for this form -->
........


Comments are great for saving places for all of our content.
For example, say you have an advertiser with a banner and just below his banner you have room for one more banner, just comment that this is where you can place a new add.
Example:
CODE
<!-- Start Foo.com's Banner Code Here-->
<A HREF="http://www.foo.com/foo_sale.html"><IMG SRC=="http://www.foo.com/foo_sale.gif"></A>
<!-- End Foo.com's Banner Code Here -->

<!-- To Quit Losing Money Place Advertisement Here!;) -->

<H1><CENTER>My Title Here</CENTER></H1>


This works great for code you don't know how to write yet as well.
Example:
CODE
Fill in the form below to order your free money:<BR>
<!-- Use some of my money surplus to learn how to add an HTML form here! -->

If you have any questions <A HREF="mailto:jdoe@foo.com">Email Me!</A><BR>


Okay here's an example of what didn't work:
CODE
<FONT COLOR="RED">  <!-- Yellow font does not work here you already tried it three times! -->


Another method I use to help keep track of the flow of HTML is indenting.
Example:
CODE
<HTML>
   <HEAD>
       <TITLE>
           My Title.
       </TITLE>
   </HEAD>

   <BODY>
       Body content here.
   </BODY>
</HTML>


See how easy it is to check if all of your closing tags are present.
This is great if you have tables inside of tables, but will always make reading the code a lot easier.

You may have noticed that all of my tags use uppercase type. I have found that this makes picking the tags out from all of the content text much easier. When I learned HTML, tags were always like this but now validation requires lowercase type as I understand it. You will have to decide for yourself how best to write your code but I suggest that you keep in mind the possibility that someday you may need to convert your HTML to another markup language.

Tells us about your suggestions for commenting.

Happy coding, cool.gif
vujsa
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No new   98 Cookiemonster 15,294 20th March 2010 - 02:19 PM
Last post by: Ahsaniqbal111
No New Posts   10 nakulgupta 5,190 20th March 2010 - 02:15 PM
Last post by: Ahsaniqbal111
No new   28 Ed :P 9,701 16th March 2010 - 07:36 PM
Last post by: iG-Luke
No new   20 dhanesh 15,702 16th March 2010 - 03:15 PM
Last post by: iG-maze
No new   27 firefoxsilver9 31,645 5th March 2010 - 03:36 AM
Last post by: iG-Vivek Lohia
No new   116 spickid101 24,901 1st March 2010 - 10:21 PM
Last post by: iG-silentdeath16
No new   46 broli 9,553 22nd February 2010 - 08:36 PM
Last post by: iG-
No New Posts   3 jord2 1,800 18th February 2010 - 02:13 AM
Last post by: iG-Tariq Khan
No New Posts   12 Zeeshan Hashmi 5,197 15th February 2010 - 09:59 PM
Last post by: iG-thewind
No New Posts   3 FirefoxRocks 274 14th February 2010 - 03:52 AM
Last post by: mastercomputers
No new   45 wua05 6,545 14th February 2010 - 12:28 AM
Last post by: iG-StayGold
No New Posts   6 Eggie 1,532 10th February 2010 - 01:29 AM
Last post by: iG-james
No New Posts   12 Nqon 4,608 9th February 2010 - 02:46 PM
Last post by: iG-
No new   25 clovis 10,861 8th February 2010 - 08:54 AM
Last post by: iG-whiteshark0121
No New Posts   1 wutske 2,150 1st February 2010 - 09:44 AM
Last post by: iG-weGIF


Web Hosting Powered by ComputingHost.com.
HONESTY ROCKS! truth rules.
Creative Commons License