Home.
HTML (Hyper Text Markup Language) authoring guide for clean code.
Last updated 5 Feb 2002
Principle.
Clean HTML is a requirement for the DOM (the Document Object Model) to function correctly. The DOM holds information about all the objects within an HTML document, and many aspects of browser behaviour depend on it. The only way a browser can build up a satisfactory DOM is if the HTML is well formed and clean.
Site level considerations
Site level points aid in the technical project management and minimise on multiple, unnescessary errors during development. The DOM extends to the entire site if javascript is used for site navigation.
- Develop the directory structure, preferably before any documents.
- Decide what version of HTML is to be used.
- All links, urls and srcs within the site should be relative to the document root of the site
i.e. src="/content/index.html"
- Ensure that if accessibility is a high priority that it is designed in and implemented from the start.
- Try to separate content, style, and scripting as much as possible.
Document level - "well formed-ness"
- Document type should always be specified - this allows validation
- All tags within a document must nest correctly. i.e.
<p><b></p></b> is wrong.
<p><b></b></p> is right.
- It helps if the HTML code is well laid out, and easy to read.
(Do not add line breaks between td tags.)
- Use concise HTML comments freely where applicable.
- Document should contain no redundant HTML. Sometimes this is produced by HTML editors after multiple edits.
Tag (or element) level
These recommendations are looking forward to XHTML (eXtensible Hyper Text Markup Language). Adopting these now will ease the transition should it be nescessary in the future. They are not essential.
- Tags and attributes should all be lowercase.
- All attribute values should be surrounded with "double quotes".
- All tags within a document should be closed, even if devoid of content i.e.
<p></p> and <br />
- All empty elements (isindex, base, meta, img, br, hr, or spacer) should end />
- img tag should have alt attribute, and should be closed. i.e. <img src="a.gif" alt="a" />
- Attributes should not be minimised. i.e. noshade should be noshade="noshade"
- Attributes id="name" and name="name" within a tag should both be used if one or other is nescessary.
- Do not leave a td tag empty. Use if nescessary.
Validation
Validation is strongly recommended. Validation tests that HTML is well-formed, and complies with the document type. Validated HTML will generally render correctly on more browsers.
Validating CSS for errors and warnings will remove many layout problems. CSS can be validated at http://jigsaw.w3.org/css-validator/validator-uri.html
HTML and XHTML can be validated at http://validator.w3.org/
Resources
Author: sinister@computertorture.com
www.computertorture.com
Validate this page with w3.org