April 24th, 2008 - by Paul OB

This is an old question but worthy of a mention once again especially as I seem to have spent the last few days repeatedly pointing out to posters why their page isn’t displaying properly. No matter how good a coder you are no one is perfect and the odd typo or spare character will often creep into your code when you aren’t looking.

Why Should I Validate?

I don’t know the answer “why you should validate” but I certainly know why I validate.

In a recent article on Search-This a poster commented that it was unnecessary to validate HTML and CSS and served little benefit so I thought it would be wise to explain why I always validate and why it is good for me. You can then make up your own minds whether you should validate or not.

The usual response of the uninformed is that “validation is not necessary” and while I agree that validation for the sake of validation is not necessary, it most certainly is necessary if you want to keep tight control of your work and limit the chances that something will go wrong.

Probably as many as 5 out of 10 calls for help that I receive are things that could have been solved by simply running CSS and HTML through the W3C validation service.

Take the following code for example which is a snippet from a recent call for help.

  1. body{
  2.     background:#fff;
  3.     color:#000;
  4.     font-family: Verdana, Arial, Helvetica, sans-serif}
  5. }
  6. #outer{
  7.     width:300px;
  8.     height:200px;
  9.     background:#ff0;
  10. }
  11. p{color:green}
  1. <div id="outer">
  2.     <p>testing</p>
  3. </div>

If you run the above code in Firefox you will see that all the styles for #outer fail to show up. Although the CSS is just a few lines the error is quite hard to spot straight away. Now imagine if the file was hundreds of lines long; the task of finding the problem would be even harder. As soon as you see that something is wrong the first step should be to run the CSS and HTML through the validator to see what it has to say about the code.

Running the above CSS through the CSS Validator flags an error straight away.

Sorry! We found the following errors (1)
URI : file://localhost/TextArea
5 Parse error – Unrecognized }

Straight away we can see that there is a stray closing bracket causing #outer to become unrecognized and the styles to not get applied. For finding errors like this and other errors such as mis-typed properties and values there is no quicker way to spot the exact error than simply running the code through the validator before you start to blame the browser.

More advanced coders can get away with validating their work less frequently during development but for beginners it is a must and should be done frequently. In this way, silly errors are avoided and the beginner is also alerted to the fact that they may be using an incorrect property or value.

It’s basically like using a spell checker which will fix your words but doesn’t mean that you can write anything sensible. You still need common sense and to have some idea of what you are doing.

When you’ve looked through as many sites as I have (over 20,000) you know that validation is necessary to weed out all the silly errors and typos that creep even into the best code.

I never validate my pages just so that I can put a sticker on the page (which I don’t do) but I do validate my page to see what errors are on the page and then make a decision to live with them or not. If the errors are missing div tags or typos then I will fix them.

If the error is because I am using a non-standard proprietary CSS then I can live with that as long as I understand the implications. Validating your page regularly will keep the code clean of silly errors and allow you to get on quickly with the job in hand.

It’s basically like using a spell checker which will fix your words but doesn’t mean that you can write anything sensible. You still need common sense and to have some idea of what you are doing.

Validation for the sake of validation is a different matter but validation for the sake of weeding out silly errors and typos is a must and I strongly recommend doing this to save at least some hair-pulling.

Of course just having valid code does not mean that the page will be rendered correctly but it does at least allow you to look in the correct place for the error when something is not right. Too many times I see the browser blamed for something which was an error in the author’s code and not the browser’s fault at all. The fact that one browser may display the code OK and another may not does not mean that either browser is wrong but just they may have different procedures for when errors are encountered. Using the correct code in the first place would have avoided the issue at stage one.

However, I will agree that the validators may appear a little unfriendly at first but understanding the validator is another skill that needs to be learned (along with all the other things a web developer has to cope with). It’s worth the effort and will pay dividends in the long run.

“Why should I validate” is still therefore a valid question with an easy answer.

“It will save you time and effort and also shows you care about your work”.

7 Responses to “Why Validate”

1 Marko Novak

I agree with your point. Every web designer should validate their code. Browsers nowadays dismiss some mistakes in code and display designs correctly even though the code has error in it.

Example: If you forget to close tag in your html code, Firefox would still display it correctly, but other browsers won’t.

That’s way validating your code is very important.

2 James

I totally agree with you paul.

I always thought of validating as an error-checking procedure more than anything else.

I must say that I hate when people get into semantics about this stuff though… The problem is that some web “professionals” see it as a badge or some kind of additional skill worth mentioning – surely validation, along with coding semantically etc. are just part of the “web designer / developer” package, or at least they should be.

3 Max

To people asking “Why Should I Validate?” I usually reply this:

HTML and CSS have rules. And you do not need a master in computer sciene to learn them. So learn them or do not develop for the web or at least don’t charge money for it.

Just because we have error-tolerant browsers (a bad thing imho) does not mean, we can use HTML and CSS as we see fit. That is just plain lazy and ignorant and it is unprofessional.

If you do not care about valid code, then you are not a serious webdeveloper. It’s like an architect who does not care about statics.

If I was to order a website and it wouldn’t validate, I’d complain about it and ask the developer to correct it. Because I ordered a website.

Validation is Quality Assurance – for you and your client. It is not optional.

4 Paul OB

Thanks for all your comments and some good points raised 🙂

5 BeCareful

Whilst it is true that coders should attempt to validate their coding, just because coding validates does not mean that it displays as intended.

It is far more important to have a site display correctly in the major browsers than to have it validate. Often this might be as simple as 1 or 2 lines of code that allow the site to be displayed in all browsers but also create a situation where the site no longer validates without “errors”.

So, whilst it is good practice to validate, and correct any bugs that might be causing your site not to display properly, it is also wise to ensure that browsers other than the one you are using, also display the coding correctly.

[…] Validation is not just a niceness, it’s a necessity. Paul O’Brien has done an excellent job explaining the significance of validation in his article Why Validate. […]

7 DaveLL

Disagree with validation being something that is required. I can see your point of using validated code for error checking being useful for a novice coder, but as previous commentators have already mentioned, valid code does not necessarily = code that displays properly.

It’s much more important to focus on good clean cross browser compatible code rather than if your code validates according to the W3C.

mulberry sale spyder womens jacket cheap new balance 574 mulberry outlet cheap new balance 574 arcteryx outlet mulberry sale spyder womens jacket mulberry sale spyder womens jacket mulberry outlet mulberry outlet new balance 574

Popular Articles

Top 10 Commentators


Subscribe to this feed! Subscribe by Email!

Random Bits Podcast

You need to download the Flash player from Adobe

Blogs Worth Reading