Freitag, 14. September 2007

Why you should write valid HTML code

...because validity is important.

What does validity mean?
Validity of HTML code means that the code simply has no errors in it. An error could be a not (correctly) closed tag or a missing doctype declaration. It is a common mistake to think that websites that are displayed correctly are automatically valid.
The correct syntax and usage of HTML is maintained by the World Wide Web Consortium (W3C)¹ since 1996.

What is the problem?
HTML is a global platform independent standard. Billions of people can visit your websites. Or should I say billions of different computer configurations can visit your websites?
For now its not possible to create websites that look the same to every possible browser/operating system/screen resolution/javascript/... combination and configuration.
The Browsers are the main part of this dilemma. It is them who understand HTML in different ways and manners – What results in quite different looks.
Of course there are dirty hacks to detect browsers and change the html or css code depending on the result – But thats really a very dirty hack.

How can this happen if there is a HTML standard? Well... After the Netscape Navigator was displaced by the Microsoft Internet Explorer in the late 1990s² Microsoft's browser was nearly unrivaled. There was apparently no need for Microsoft to improve the compatibility to other browsers. They began to „understand“ HTML code in their very own way and many webdesigners began to code their HTML in the way the Microsoft Internet Explorer understood it.

A few years later (around 2002) Mozilla came up with the Firefox Browser. People began to like it and the Microsoft Internet Explorer was losing market share. From now on there were two big browsers in the game.
Because of the long year dominance of the Microsoft Internet Explorer many websites were coded to be „best viewed with Internet Explorer“ - or: not valid! Mozilla had to change the behaviour of its Firefox Browser to display those websites as good as possible. But they were not able to do that without breaking some rules of valid HTML.
None of the big browsers reads HTML code in the completely correct way – They even read it in different (wrong) ways.
So coding HTML that is displayed the same by all browser is like talking to a japanese and a german in english if none of them speaks another language then their natural one. - Almost impossible.

What to do?
Right now it seems like there was no way out of that. It is just like a vicious circle.
Someone has to break out of this circle! And to me it looks like it's us – The webdesigners!

The main requirement for an agreement between browser developers about understanding HTML code in a valid way is to have many many many valid websites in the world wide web. If this should ever happen our digital lifes would get much easier. Imagine being sure about the display of a website in every popular browser just by validating the code. Lovely.

Sounds great! But how do I write valid HTML?
Because this is a huge (but not really hard) part of Webdesign I cannot tell you how to write valid HTML code here exactly.
I think the best way is to intially create a website the way you always did. Then use the W3C Markup Validation Service3 and check the website. Fix the errors step by step until you get the green „This Page Is Valid [html type]“ message.

Dont forget to place the „valid“ Icon4 on your validated website.

It is your turn now! Write valid HTML code and make the first step to a less stressful work and world.


1) http://www.w3.org/
2) http://en.wikipedia.org/wiki/Browser_wars
3) http://validator.w3.org/
4) http://www.w3.org/QA/Tools/Icons

Keine Kommentare: