3. HTML Code Guidelines
3.1 Directory Structure & Naming Conventions
3.2 General Tag Formatting Conventions
3.3 Commenting Conventions
3.4 Miscellaneous Conventions
3.5 Tag-Specific Format Conventions
3.6 Unused Tags (depricated, legacy)
3.7 WYSIWYG Code Generation
| Directory Structure |
To assure that there are not problems or difficulties moving a site from our internal development servers to the servers where they will eventually reside, it is important to bear a few rules in mind: |
| |
All directory (and file) names should be written in lowercase. Although Windows NT environments are not case-sensitive, Unix based servers are rigorously case-sensitive. A site working perfectly on an NT server could result in dead links on a Unix box. |
| |
For the same reasons as above, directory (and file) names may not include any spaces, slashes, or other separators except underscores and hyphens. |
| |
Unless the operating system and structure of the hosting server are known in advance, all path names should be relative. This way if a site has all images pointed to <img src="images/graphic_01.gif"> it can easily be moved up or down a directory and all image locations can easily be searched and replaced. |
| |
All sites should make use of "images" and "common" directories. Depending on the size of the site, there may be one "images" and one "common" directory, or a directory in each section. If there are individual images that are used in several places on the site, they should always be in "common/images" on the root level of the site. |
| |
Whenever possible, directories containing HTML documents (not image directories) should contain an "index.html." The main reason for this: if a user tries to go straight to a directory (www.onaicul.com/work/widgets) we don’t want them to see either a "permission denied" message (if we don’t allow directory logging) or a tdsting of all the files in the directory (if we do). |
| Naming Conventions |
As early as possible in the construction of the site, decide on a naming convention that combines brevity and clarity. Make sure that the designers, programmers, and HTML writers all know and understand the system. |
| |
Filenames should be as descriptive as possible. Names should not exceed 25 characters and should use the '_' character to separate logical name elements. |
| |
Some examples include using the word "nav" for navigation bar graphics, "home" or "sub" for a home or sub-page graphic, or any other system that makes sense and remains consistent. Use underscores to separate elements of the file name such as "h_nav_head.gif." Plan out the naming conventions and check the logic with someone else working on the project. |
In accordance with the W3C (World Wide Web Standards Committee), The Onaicul Project has adopted the following HTML code outline. The intent of this outline is to ensure browser compatibility with all HTML code as well as to preserve consistency between and within projects. The outline should be adhered to as strictly as possible whenever possible. That said, it is also noted that engineers may compromise components of the outline when necessary to improve readability, functionality, and/or consistency.
Although every company probably has different HTML standards, it is important that everyone at The Onaicul Project write it the same way. The following are some of the style guidelines for writing HTML:
All tags are lowercase (NOT CAPITALIZED). Your favorite HTML editor should be customizeable (Options>Settings>General) so that the automatically inserted tags are lowercase. In keeping with the new W3C recommendation for standardized and forward compatible HTML code we are asking that you try and keep all tags lowercase.
When describing parameters of an image, use quotation marks around all numbers. Always include the WIDTH and HEIGHT tags (to improve the load time of the page), and include BORDER=”0” particularly when the image is a link (some browsers will default to putting a 1 pixel blue border around any hot image if the parameter is not set to zero). ALT tags can be very useful for describing the Content of that image so that if the image doesn't load, at least the audience will know what the image is about (what it links to, etc).
The following commenting conventions should be used when writing code:
- Format
- The HTML commenting tag uses the following format:
<!-- Comment Goes Here //-->
Comments may span more than one line. As long as the tag begins with <!-- and ends with //-->. It is also a good idea to put any code within the <script> tags within comments. This is done because to avoid older browsers displaying the (javascript) code on the page.
- Code
- All code should be thoroughly commented. Comments should be used to provide explanations of logical code blocks. As a general rule, any group of code which is indented/nested should include a comment describing the code. In most cases, comments should not take up more than one line. All comments should be descriptive enough to provide a basic explanation of what the code does.
- Unnecessary Comments
- Lines of code which have been commented out for testing or re-writing purposes should be uncommented or removed in the finished product.
META tags are a subset of the document header tags that allow people and machines that search and index the internet to see a short description and list of keywords related to the Content of your page.
It is strongly recommended that all Onaicul Project websites include meta tags. META tags are especially important when your site pages have little or no user-oriented text.
3.5.1 Formal HTML
Coding Style
This section outlines certain formatting-related HTML
specifics that should be observed when compiling Web-oriented documents.
Not all HTML specifics will be covered, as in most cases it is possible to
compile an HTML document without even dealing with the code itself.
However, it is advised that the instructions outlined in this section are
followed, so that all Content Project documents
coded in HTML are:
- easy to read
- easy to re-use
- easy to modify.
3.5.2 HTML Tags
Tags are specified with the
Less-Than (<) and Greater-Than (>)
operators. These operators will henceforth be signified by the title Tag Specifiers. Text affected by Tags shall be
known as Tagged Text from this point on. Text
to be defined within a Tag and its terminator would be within its Tag Domain.
Primarily the 3 properties that 'decide' a Tag is the Tag Name, Tag Attribute,
and Tag Value.
All Tags (and those Contents within those tags) should be
entirely in Lower Case. Absolutely all of each
Tag's Value(s) should be stated in Double
Quotes (").
Thus, Tags consist of the following properties:
| HTML:
|
<font size="2">something</font> |
|
Tag Specifiers |
< > |
|
Tag Name |
font |
|
Tag Attribute |
size=
|
|
Tag Value |
"2" |
|
Tagged Text |
something |
|
Tag Terminator |
/font |
Tag Terminators are not required in some cases. It
shall be discussed in the following section.
3.5.3 Tag Terminators
Current HTML Coding Standards specify that certain Tag
Terminators are optional; not compulsory. Content Project Style suggests that some of these Tag
Terminators with an 'optional' status will not be ignored-- they must be explicitly stated no matter what.
From this point on, each of the
following sections shall identify those Tags which have accompanying Terminators
that must be included, or may be ignored.
Take the following example, which describes an explicit
'Compulsory' Tag Terminator:
| HTML:
|
<!-- This is some
commented HTML code. If this comment were not explicitly terminated, the rest of this document
would be considered part of the comment. --> <html> :
: </html> |
Within this example, there are 2 Tags with compulsory
Terminators. Not specifying the Terminators in these cases would result in
havoc when viewing the code.
3.5.4 Code Line
Length
HTML code should be limited to around 80 characters to a line; this minimises the need
to excessively scroll when viewing/modifying code.
If it is possible to follow-on to the next line, then do
so. In most cases, it is more of a priority to keep within this
recommended line-limit, than to abide by the other rules imposed within this HTML Coding Style.
Priorities for the use of these HTML-based rules is provided in a later section.
In extreme cases where this is
not possible, exceeding the limit is acceptable. A possible situation where the
limit cannot possibly be adhered to is when an "Anchor" tag is concerned:
| HTML:
|
....v....1....v....2....v....3....v....4....v....5....v....6....v....7....v....8 <a href="http://www.this_is_an_example.com.au/directory/subdirectory/this_is_an_example.html"> This is an Example</a> |
Tag Contents (that is, those components between Tag
Specifiers) should not be split on to separate lines. The exception would be for
Table and Images Tags, which sometimes require multiple attributes that cannot
be specified on the same line.
The 'cheapest' method to sticking as close to the character
limit (as opposed to purchasing an HTML-editor that does it all for you), is by
resizing the window of the code-editing program to 80 (monospaced) characters.
One can use the sample of
numbered text (above), to calculate the preferred width of an editing window--
copy the text into the editor, and then resize the window corresponding to the
space that the copied text takes up.
| eg.
|

|
|
Resized Window displaying only
80 Characters per line
|
3.5.5 Indentation
Indentation is necessary for HTML code, so that a
certain portion of code can easily be identified within the document.
Understanding where indentation
should be performed is directly related to the use of Tags-- knowing when and where tags are applied permits
us to say that certain tags have more precedence over others.
In terms of the Style specified
here for coding Content Project documentation,
those tags which are considered more significant decide the indentation that
should be performed on the code.
3.5.6 Indent Size
The Indent Size, or "Tab
Width" should be 2 characters. If Tab/Indent facilities are unavailable
with the editor in use, implement indentation using 2 character spaces.
3.5.7 General Tag Recommendations
Paragraph Tags
Paragraph Tags should be used very sparingly to
ensure ease in readability. All Paragraph Tags should
be specified on a new line. Additionally, all Content
within Paragraph Tags should be indented to emphasise
the Paragraph Tag's domain.
Where possible, each section within a document should
only contain one HTML Paragraph Tag set (" <P> ", " </P>"). When line breaks
between paragraphs are necessary, two HTML Line Breaks
(" <br><br> ") should
be implemented in place of Paragraph Tags. The exception
to this rule is when a section of HTML Text is separated
by a "Non-Paragraph-Text" object.
| eg.
|
| HTML: |
: This is the last sentence in the
first paragraph. <br><br> This is the second paragraph. Note the line break being used between the first and
second paragraphs. </p>
<img
src="sample.gif"> <-- Non-Paragraph-Text Object
<p>This is the third paragraph. This paragraph cannot belong with the first two
paragraphs because a Non-Paragraph-Text object is
'obstructing' it. <ul> <li>This is a list item. <li>This is also a list item. </ul> Note that an ordered/unordered list
can be included. </p>
| |
In other words, there are some 'objects' that are
allowed within a Paragraph Tag domain, and others that should not be. In
the context of the Document
Content Template, the sorts of objects that are not recommended within
Paragraph Tags include the following:
- Note Box
- Example Text (Box)
- Image
- Table
Those objects stated above should not be included within a Paragraph Tag Bulleted
and Numerical (Unordered and Ordered) Lists are among
those 'objects' that can be included within a Paragraph
Tag domain.
Font Tags
The Font Tag is depricated in favor of Style Sheets. When it is neccesary to use font tags the following guides should be adhered to:
A Font Tag must be terminated before another Font Tag is
allowed to begin. There should not be any overlapping of such tags.
However, other tags may be applied within Font Tags, and Font Tags may also be
applied within other Tags-- the context depends on whether the font style should
affect several words, or a section of text.
Sections of text within the body of an HTML document should
not be left without
being defined with a Font Tag.
Formatting Tags
| HTML:
|
<b>This text is set to 'Bold'</b> <i>This text is set to 'Italics'</i>
<u>This text is set to 'Underline'</u> |
This text is set to 'Bold' This text is set to
'Italics'
This text is set to 'Underline' |
Ensure that Tagged Text does not begin or end with
spaces.
| eg.
|
this is <b><i>some </i></b>text. |
incorrect
|
|
| this is <b><i>some</i></b> text. |
correct |
Ensure that all elements nest. Most browsers won't care
if you overlap elements, but it is probably a good idea
to try to keep to this rule. Newer versions of HTML require
that you nest alll tags correctly. You should unclose
the tags in reverse order - i.e. last opened - first closed.
| eg. |
<p>Be <b>bold!</p></b> |
incorrect |
|
| <p>Be <b>bold!</b></p> |
correct |
Bulleted & Numbered Lists
The equivalent names for "Bulleted Lists" and "Numbered
Lists" in HTML-tag convention would be Unordered Lists
and Ordered Lists respectively.
| HTML:
|
<ul type="disc"> <li>list 1</li> <li>list 2</li> <ul type="circle"> <li list 2.1</li> </ul> </ul> |
|
Anchor Tags
| HTML:
|
<a href="http://www.example.com/html/example.html">This is an Example</a> <a href="example.html#SpecificSection">Specific Section</a>
<a name="SpecificSection"></a> |
Anchor Tags should be used
when identifying links to either another area of the same document, or another
document altogether. An anchor can either be a Link Source or a Link
Destination.
All anchor tags, in conjunction with its tagged text,
should remain on the same line.
3.5.8 Tables
Table Tags should appropriately be indented and
specified on a new line. All successive table-related Tags should also be
indented.
Table attributes are
recommended to remain on the same line. However it is anticipated there may be
many instances where they span multiple lines in order to remain within the also
recommended 80-character line limit. Attributes that span the next line should
also be indented.
| HTML:
|
<table width="100%" border="0"
cellspacing="0" cellpadding="5" bgcolor="#c0c0c0" bordercolor="#c0c0c0"> <tr
colspan="2" valign="top" align="left"> <th width="50"> <font face="Arial,
Helvetica, Sans-Serif" size="2"> Heading </font> </th> <td width="95%"> <font face="Arial,
Helvetica, Sans-Serif" size="2"> Contents </font> </td> </tr> </table> <br>
|
Indentation for Table Tags are especially important,
which greatly aids in modifying the table Contents when necessary. For the above
example, inserting a new row into the table only involves duplicating the
section signified by the <tr> Tag and corresponding Terminator.
3.5.9 Spacing
Spacing is necessary for HTML code, so that a certain
portion of code can easily be identified within the document.
This assists in readability and reusability.
In some cases adding an extra line break or space before
closing a "</td>"
will result in extra space in the cel when viewed in a
browserl. You can avoid this bug by deleting all the extra
white spaces and line breaks between the last tag and
the closing "</td>"
| HTML: |
<table width="100%" border="0">
<tr colspan="2" valign="top" align="left">
<td width="50">
<font face="Arial, Helvetica, Sans-Serif" size="2">
Heading
</font></td>
<td width="95%">
<font face="Arial, Helvetica, Sans-Serif" size="2">
Contents
</font></td>
</tr>
</table>
<br>
|
Obsolete tags (also known as Unused Tags or Depricated tags) can be harmful to a website. There are certain tags that were really popular in early versions of HTML that have since been modified or ommited from more recent W3C specifications.
It is a rather tedious process to list all of the unused tags, so instead I'll list some good resources to learn more about which tags form part of the current recomendations. The most recent W3C reccomendation will always have the final word on what is and isn't HTML.
Sizzling HTML by Jalfrezzi has an excellent resource that lists all the current valid HTML tags and their corresponding support in different browers at <http://vzone.virgin.net/sizzling.jalfrezi/frames/findex.htm>
"A comprehensive guide to writing web sites." -- http://vzone.virgin.net/sizzling.jalfrezi/ Text Only Version
To this day Kevin Werbach's "Bare Bones Guide to HTML" remains the essential quick-reference tool for HTML developers. Make sure you don't forget to download the handy text-only version and keep it somewhere on your hard disk for quick reference ;)
Brian Wilson has painstakingly created a fully functional online HTML reference manual. This is an absolute must to bookmark. You can also download a zipped version of the entire reference. Years from now you will still remember "index DOT html".
The proliferation of HTML and the explosion of the World Wide Web has resulted in a parallel explosion and proliferation of WYSIWYG (What You See Is What You Get) editors that generate HTML and JavaScript. Although at first glance these editors seems to take some of the time out of HTML layout and production, in reality they often wind up costing more development time in the long run.
HTML Editors that do not allow personalization to the detailed level should be avoided. Redundant and unnecessary code, overcomplicated table structures, unformatted and incomplete tag and attribute statements, and poor nesting formats are just a few of the many problems these editors can introduce into code.
Still, advantages exist in using a professional WYSWIG editor when you know what you are doing. Dreamweaver by Macromedia stands out as one excellent example of a fully customizable robust HTML editor. It can be customized fully to produce code exactly how you like it. Online, resources like Webmonkey have devoted time to discussing different WYSIWYG editors.
HTML Code Example
Here is an example of proper HTML Code in compliance
with the proposed code guidelines.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>xhtml</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#F2E9DB" text="#000000" link="#CC3333"
vlink="#6699CC" alink="#FF6633">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" bgcolor="#F5F5F5">
<h1>Advantages of XHTML</h1>
<h2>The Extensible Hypertext Markup Language</h2>
<h3> What is XHTML?</h3>
<p> XHTML 1.0 became an official W3C recommendation on
January 26, 2000. A W3C Recommendation means that the
specification is stable, that it has been reviewed
by the W3C membership, and that the specification
is now a Web standard.</p>
</td>
</tr>
</table>
<hr />
<p><font size="2">
<b>Last Modified</b> :
<script type="text/javascript" language="javascript">
<!--
document.write(""+document.lastModified+ "")
-->
</script>
<br />
Author: <a href="http://www.onaicul.com/">
The Onaicul Project</a></font></p>
</body>
</html>
|
View this example code in your browser
Validate
this page against it's DOCTYPE
Validation by WDG
HTML Validator
DOCTYPE: Document
Type Declaration
Every HTML document must have a Document Type Declaration.
This means exactly what it sounds like: a Document Type
Declaration declares the document to be of a specific
type. In our case this type is HTML.
HTML: <html>
The first element will always be the HTML element. All
HTML documents have an HTML element, which contains all
the other elements. The HTML tags should (as well as all
other tags) should always have a closing tag: </html>
Head: <head>
The difference between the head and body of a document
is that the head contains mostly information about the
document, while the body contains the document itself.
Scripts, stylesheets and meta tags all normally go within
the <head> tags with some exceptions.
Title: <title>
The TITLE element is a very simple element. It cannot
contain anything but text and that text is the title of
the document.
Meta: <meta>
HTTP-Equiv: The browser or HTTP server uses this information
to process the document. Some HTML editors add this tag
automatically. It is a good idea to include it in all
your documents (just like the DOCTYPE declaration). In
this case the code is telling the browser that it is an
HTML/TEXT document in iso-8859-1 encoding.
Body: <body>
The Body tag holds alot of power over an html document.
Without this tag the page WILL NOT WORK!
One mandatory attribute for the body tag is the page's
background color or bgcolor. If a page is missing
the bgcolor tag it will show up with a grey background
on several browsers. It is also a good idea to set your
text , link, alink and vlink
tags. These tags allow you to specify the colors for the
different kinds of text in your documents: text color,
link color, active link and visited link, respectively.
Table: <table>
The table tags should always be closed. Cellpadding,
cellspacing, and border are all good attributes to include.
Header 1 : <h1>
Visual browsers typically render H1 in a large, bold
font. Authors can suggest a presentation for H1 through
style sheets. The heading level should be chosen based
on the heading's importance and placement in the document.
An H1 is typically used as the main heading for a document.
The H1
element defines a level-one heading. A document generally
should have exactly one H1 element to mark the most important
heading.
The H2
element defines a level-two heading. This heading is more
important than an H3 but less important than an H1.
The H3
element defines a level-three heading. This heading is
more important than an H4 but less important than an H2.
Paragraph : <p>
The P element defines a paragraph. The closing tag for
P is optional, but its use prevents common browser bugs
with style sheets.
HTML does not specify a presentation for the P element.
Visual browsers commonly use block paragraphs with no
first-line indent and separated by a blank line, but some
browsers allow the user to specify a different presentation.
An author can suggest paragraph indentation and spacing
using style sheets.
P
in W3C
HTML 4.0 Recommendation
Horizontal Rule :
<hr
/>
The HR element defines a horizontal rule for visual browsers.
While this element is inherently presentational, it can
be used structurally as a section divider. It is always
good form to close an element. Empty elements must either
have an end tag or the start tag must end with />. (<br
/> should be closed as well.)
Font : <font>
The FONT element, deprecated in HTML 4.0 in favor of
style sheets, allows authors to suggest rudimentary font
changes. Use of the FONT element brings numerous usability
and accessibility problems, as discussed in the article
Font
Face Considered Harmful?
Bold : <b>
The B element suggests that text be rendered as bold
text.
Script : <script>
The SCRIPT element includes a client-side script in the
document. Client-side scripts allow greater interactivity
in a document by responding to user events. For example,
a script could be used to check the user's form input
prior to submission to provide immediate notice of any
errors by the user.
|