We have all visited a website that shows the “Valid HTML” and “Valid CSS” image badges in the footer. But how many times have you clicked on them to see if the code was actually valid? Well I have made a habit of doing this, clicking on the links. The most annoying websites are those that have the icons but don’t link to the testing pages.
So why do I click on the links? Well mostly because I find that all the websites that have the links on them are straight from the 1990’s (indeed a few of them also have the “Designed for Netscape” or “Designed for Internet Explorer” badges in the same footer) but mostly because there is something quite hilarious about the links, of all the times I have run a W3 Validation check, I can only remember 1 time when the code has come back completely valid. So why is this? Well you can write as much compliant code as you like but sooner or later there will be one mistake.
“But all the code on the internet should be valid, otherwise the browsers will not render it correctly!!!” this is simply not true. Run a W3 Validation check on any major page you want, Google, Yahoo, Bing, Facebook, Twitter, JohnCol.es, none of them validate. Modern Browsers (read as “anything other than IE”) have very high tolerances for errors. A <style> tag shouldn’t be in the <body> tag but many sites do it.
Before I go any further I must say that the standards behind the validation is important, the actual validation is not.
So is valid code needed? Yes and no. When learning a language it is very important to get to know exactly how it is meant to be written, as cleanly as possible. Some would argue that error correction is a bad thing as it allows you to write sloppy code. I am the worst for this when developing quickly. There are many times when writing server side applications I use variables when I should use an array for global storage leading to more RAM use but because of modern computing we can get away with it. Valid code is not the be all and end all. There are occasions when you can validate some code as working but a browser will not display the expected outcome.
My advice to anyone who is programming, testing > validation. Try validating your code, if there are any major warnings then solve them other than that try and test on every platform you can do. We do this at Kloodle, we have PCs running multiple versions of Windows with various different versions of browsers, Linux distributions then a selection of mobile devices, from the iPhone 5 to a Pink BlackBerry Curve 8520. If the code runs as you expect it to then you have no issues, if not the validation results may give you a hand in tracking down the issues.