indiWiz.com

Subhash's Tech Log

Writing HTML

with one comment

Programmers are often required to write HTML code. Recently, on reviewing such code, I found some glaring mistakes. Based on this experience, I have assembled some points which programmers should note when developing HTML.

Version of HTML

Before writing HTML, decide upon version compliance. HTML 4.01 and XHTML 1.0 are popular choices.

Specify Version of HTML as DOCTYPE

For HTML 4.01 it is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

For XHTML 1.0:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

For a detailed list, visit: http://webdesign.about.com/od/xhtml/a/aa011507.htm

Don’t use deprecated elements like <font>

<font> has been deprecated since version 4.01 of HTML.

Use CSS for styling

For styling purposes (specifying font, color, background-color, border, etc.) use only CSS. For example, for setting the background of a page, the earlier method is:

<body bgcolor="blue">

This is better written as:

<body style="background: blue;">

Open/Close Elements

Please ensure you open and close the HTML elements in proper order. Always have the discipline of closing open elements.

Indentation

HTML is also source code which is maintained by humans. Please respect yourself and the people who will be maintaining it later: write readable HTML with proper indentation.

Validate HTML

Use a proper validation service before publishing your HTML. You may also use tools like xmllint also to validate your HTML.

Test in target browser

All our development systems are Linux. We developers test our HTMLs in Firefox. But our clients use IE. Situations like these demand additional testing effort in IE.

Written by Subhash Chandran

April 21st, 2009 at 11:16 am

Posted in Software Dev

Tagged with , ,

One Response to 'Writing HTML'

Subscribe to comments with RSS or TrackBack to 'Writing HTML'.

  1. This is another validation service: Validator.nu.

    Subhash Chandran

    23 Jun 09 at 9:50 am

Leave a Reply