The importance of validation
If you have been doing Web development in HTML, XHTML and CSS, then you will probably have heard the term "validation" thrown about from time to time. And if you have not; then it was time you woke up and started contemplating another career. Seriously, this is something every Web developer and Web designer should know about.
Now then, this article will give an introduction to what validation is, explain why it is considered a good practice writing markup code that conforms to the standards set by The World Wide Web Consortium, as well as giving some motivational hints to why this is advantageous for you and your site.
Developers with good knowledge of XHTML should already be aware of this and could probably skip this article, mainly because this topic has been discussed to death a million times already.
So, what is all this about validation then?
Validation can be explained as the process of checking if your markup code conforms to a certain Web standard. In layman terms this can be described as spell checking for errors, where the language beeing checked can be for example XHTML or CSS. What happens when your are validating, is that you are checking if the markup code follows the rules for the standard, for example as defined in a Document Type Definition or a CSS Specification.
There are several standards one can conform to, but the most common ones in this context are HTML, XHTML and CSS. The teacher checking your grammar will in this case be W3C, using either the Markup validator or the CSS validator. You can read more about what validation is in the W3C article Why Validate?
Why should I even bother?
This is acctually a very valid question (no pun intended), and is something that I have a hard time explaining to novices time and time again. Some of the usual arguments can that "my page displays fine", or that "it takes to much time to check it". This sounds more like complaining to me, and going back to the spell checker example above, just imagine your common book. A book can very well contain some spelling errors and still be readable, but if the number of errors becomes to great, then misunderstandings are bound to occur.
The same goes for Web pages: your browser will forgive some coding errors. But induce to many errors, and your markup code may get interpreted the wrong way. This may lead to unpredictable results, like your elements showing up in the wrong place, text not displaying correctly, etc. Errors like these are a sure way to push away your visitors.
Also, if you have a non-valid page (a page that by default does not conform to a standard), what you are doing is relying on error correction in the browser itself. This means that the browser expects to find errors, which in some cases might be a good thing. But this is also why in some cases your page may display fine in one browser, while in other browsers you can hardly recognize it. Internet Explorer has been notorious for this in the past.
Some good reasons
Validation is therefore your first line of defence against errors. If you validate your code and it checks out, then you can always be sure that any strange behavior is not due to you forgotteing to close a tag or nesting elements in the wrong order. This in in turn makes it simpler to locate errors and perform testing, which in turn gives you more time to work on the acctualy design instead of constantly having to write hacks to make your bad markup code display correctly.
Another reason to validate is for the sake of professionality. More and more designers and developers are recognizing the value of writing quality markup code that validates. So if you are working on a project and don't validate your code, this may very well induce errors. These errors are something your team members may very well notice, and may give them the impression that you don't bother with standards, or is just doing sloppy work.
A third and very important reason is search-engine optimization. Poorly written web pages may make it hard for search engines to interpret the content, and this in turn may directly impact your search ranking. Read more about how poor code can affect your ranking.
As already mentioned; there are more than enough rants about this topic on the Web already, so I don't think I need to elaborate it any further. A good article is Ten reasons to learn and use web standards, but if you still need more reasons; try searching for why validate html on Google. This should give you more than enough reasons if you're not already convinced.
This sounds like a lot of work, is it true?
A common misconception is that writing code that validates is a lot of work. This may be true the first time you validate your page, and the validator throws 1001 errors. But after a while you will do it more or less automatic. A good practice is validating the page every time you do some major changes, and one of the positive side effects of doing this (in my experience) is that you quickly will find your code quality improving. This is because you will learn to recognize what is valid and what is not, and after a while you might not even need to validate. But it is still a good idea to do so every once in a while.
Ok, I'm convinced. Where do I validate?
Two of the most common validators are W3C's Markup validator and CSS validator. Here you can validate by url, by file upload, or by direct input. The easiest way to validate is to provide direct links (referers) to the validators from your page. For example as I have done for this page, putting valid XHTML and valid CSS links in the topmost section:
<a href="http://validator.w3.org/check?uri=referer">
Valid XHTML
</a>
<a href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.rpersen.no/assets/templates/rpersen/stylesheet.css">
Valid CSS
</a>
Summary
So to sum it up, this is what you should try to remember:
- Validation is used for spell checking your code for errors.
- Good markup gives your site a professional feeling and improves your search ranking.
- Bad markup affects your search ranking and causes inconsitencies accross browsers.
- It is considered a good pratice, and it's not hard once you get into it.
- Always try validate after editing, this way you won't have to do it all at once.
- Don't give up, it's not as hard as you think.
As always, if you have any questions or comments, feel free to contact me.


