Friday, 21 November 2008

What flavour of HTML should I use?

Something that has plagued the web develop since the days when Netscape and Internet Explorer 2.0 were battling for the web market is how to code a web page. It is a strange question to the uninitiated since surely I want to code it a way that will look the same on all browsers.

Herein lies the problem. For acceptable and unacceptable reasons, various browsers do not agree on how to lay out a page. In some cases, a browser is simply not complete and does not support a particular css style. You have to drop its use but then you can't do what you want so sometimes you have to use a workaround. Sometimes the specification is not clear about what attributes do and different browsers have interpreted them in different ways. Often in CSS you should default the common candidates for this like font and paragraph spacing to 0 at the page top level and then apply them specifically at each other level to be explicit. Sometimes, browsers are simply wrong and a classic example was the old broken box model in Internet Explorer. Does the margin go inside or outside the specified size of a div? What about the padding? The border? Again there were various workarounds and you would now think that things have been mostly sorted in the latest browsers.

You would be correct but there are two problems. 1) The newest technologies are always likely to be incomplete or misunderstood until the browsers are released, tested and fixed (hopefully) and 2) Many of your potential users are not using the latest browsers and maybe for one reason or another cannot use them. What this means is you have to code your page in a way that works on an older browser, with all the quirks and workarounds which means at no point can you code a page that is fully HTML or XHTML compliant. What is one to do?

It is good practice to develop a site using a compliant browser before trying it on non-compliant one and trying to fix any major flaws. Try a newer version of HTML/XHTML if it gives you something you need, there is no point being at the hairy edge of new development if all you need for your site is available in HTML 4.0

Personally, I use HTML 4.01 which is reasonably well known by now but not too old so as to be rubbish. Most browsers interpret this correctly. It is not worth trying to create two sites for, say, HTML 4.01 and HTML 5.0 since web sites are usually majorly rewritten when they are updated (if they are updated) since people tend to want something much more snazzy for their money than a change of font or colour. For this reason, any second site 'for the future' would be binned along with the first site. If you need one for older browsers, use an older HTML.

The other approach which can be slightly militant but perhaps called for is to lay out a page so it is usable on browsers that are not compliant but perhaps looks a bit rough and then put a link to a compliant browser at the bottom saying "this page is best viewed with opera/firefox/whatever" and perhaps a 'why?' link next to it which explains why some browsers do not encourage good site design and why you would like to write your pages properly. If you do this, please word it fairly, there are too many people out there who do nothing for the industry than re-enforce the stereotype of some social misfit who has nothing better to campaign for than the abolition of Microsoft and anything related to it!

If anyone has any more useful ideas then let me know.