|
Post by Mickuk on Feb 14, 2006 8:37:56 GMT
|
|
|
Post by Mickuk on Feb 14, 2006 11:06:44 GMT
Tips for writing cleaner HTML
I have heard many people complain about not being able to read HTML for one simple reason—many Web page designers simply write sloppy code. Well, it's time to pull out the cyber-mop and learn a few things about writing clean HTML. Here are my tips.
Spacing and indentation One of the truly wonderful things about writing HTML documents is that you can use whatever kind of spacing methods you like. Unlike some programming languages—such as COBOL or PASCAL—an extra space is not going to affect the meaning of the HTML, which not only gives us a chance to write more readable HTML—it allows us to have flexibility in our approach.
Indentation is perhaps the single most helpful tool in writing an HTML document. Indenting our code allows us to line up some of the opening and closing tags so that we can easily see what is a part of each tag.
By using this method of spacing, it is easy to see the separation between the actual information (links and images) and the actual code for the table. In this example, all of the <TD> and </TD> tags are aligned as well as the <TR> and </TR> tags. The actual information that goes in each cell is also aligned so that it's easy to go back and make changes later (especially if you're in a hurry).
Keeping tags in order It is considered proper HTML programming to place your opening and closing tags in a certain order. For instance, when including an image that serves as a link to another page, there is a simple order to follow: <A HREF="http://www.domain2.com "><IMG SRC="picture2.gif"></A>
Here you open a tag, insert an image, and then close the tag.
When there is extra code involved, sometimes this whole tag order business gets a little hairy. However, we should be careful to keep a consistent pattern for a couple of reasons:
It makes the code easy to read and understand It allows the code to do its job
Tags that are slightly out of order can have an adverse effect on the way your Web page appears.
As a general rule, you always want to close the tags in reverse order of how you opened them. This may sound a little confusing, so let's take a look at this code: <P><A HREF="http://www.domain.com"><FONT FACE="Verdana,Arial,Helvetica,sans-serif" SIZE="2"><B>Domain Name Text Goes Here</B></FONT></A></P>
In this code sample, there are four opening tags (paragraph, link, font, and bold—in that order). The closing tags are in reverse order (bold, font, link, and paragraph). In HTML, you have to first close the last tag that you opened and follow that pattern until all of the tags have been closed. Here's a tip: Never forget to close a tag. If you do, your HTML won't function properly.
A word about capitalization HTML code isn't case sensitive; however, it is a good idea to choose either all lower case or all upper case tags. The main reason is because it makes the document more aesthetically pleasing and easier to read. Personally, I like to use all caps when coding my tags. This provides a nice contrast to the text, which is usually in mixed case. Here's a sample: <FONT SIZE = "2">Here is my text. It's easy to read because the font tags are in all caps. </FONT>
Condensing tags One of the easiest things to do to clean up your coding habits is to condense code whenever possible. Condensing code simply means taking several related tags and making them one. For example, consider this messy code: <FONT SIZE="2"><FONT FACE="Verdana,Arial,Helvetica,sans-serif"><FONT COLOR="#FFFFFF">Insert Text here</FONT></FONT></FONT>
You can make that code easier to read by condensing it to read: <FONT SIZE="2" FACE="Verdana,Arial,Helvetica,sans-serif" COLOR="#FFFFFF">Insert Text here</FONT>
The main advantage in this example is that we don't have three end font tags. Of course, sometimes there is a certain advantage in separating these tags. In the HTML shown in Figure C, I separated the font tags because I want the font face to be consistent. However, I want the sizes and colors to vary at different points in the text. A case like this would be the only time we would need to separate the font tags. (Don't forget to close them in the right order!)
In certain cases, you'll want to separate the font tags in order to achieve a specific effect.
The importance of closing tags in the correct order really shines through here. Just by changing the placement of a few tags, you can alter the size and color of your text ;D
found this onmy freeware forum wrote it yonks ago ;D ;D
love, mick
|
|
|
Post by stef on Feb 14, 2006 16:36:54 GMT
Hi Mick Thanks......I think ;D ;D ;D love stef
|
|
|
Post by Mickuk on Feb 14, 2006 17:56:03 GMT
Hi Stef, Piece of cake ;D just jump in at the deep end i did ;D ;D ;D love, mick
|
|