Step Away from the Validator  January 7th, 2009

I spend quite a bit of time keeping up with the happenings of the software industry. Part of that is reading blogs, reddit comment threads and the like. One of the topics that seems to come up regularly is a (sometimes heated) discussion about validation.

It's often the same story. There's a guy who can't get his code to validate or notices that 'insert popular website' doesn't validate and flips out and writes a comment or something on his own blog about how we're filling up the tubes with apocalyptic, non-standards compliant, code.

I'd like to add my 2 cents to this topic.

In the Eyes of the Validator

This page (and, as far as I know, all the pages on this site) validates as XHTML 1.0 Strict, but it doesn't matter. If I hadn't mentioned it, would you notice? Would you care? If the site works for you then what difference does it make?

Is there a point of validating at all? Indeed, the fact that your site validates proves exactly nothing about the quality of your pages. What it does do is a couple of important things:

XHTML is a set of guidelines and suggestions. That's all we're talking about. It's just not a big deal if you don't pass the validator — especially if you're not passing because of JavaScript DOM modifications!

Mangling the DOM

So your site is perfect in every way. You've got your blog articles and they've got img tags and blockquote tags all nested in the 'correct' way. Nothing strange going on at all, you've even tracked down all of those pesky missing alt attributes. Everything passes the validator with flying colors.

I passed, whatever.

But then you decide that those links that go outside your site really shouldn't take the user away from your pages, that's annoying. You write some JavaScript that looks for links with rel='external' and sets their target attribute to _blank...

... via some magical simple JavaScript such as ...

... we arrive at ...


Still passing the validator if you give it a URL, but if you paste in the modified code (say, from Firebug or whatever) as the markup looks after the JavaScript has had it's way with it... well...

Validator Fail

Ok. So what? Of course there are other ways to get a link to open in a new tab, and there are often other ways around similar problems to this. Maybe you'd suggesting switching to Transitional instead... That's my whole argument! Switch to a different validator, perhaps Transitional, perhaps "does it work for my users?" What you shouldn't do is spend two weeks forcing the page to pass some artificial test that has no impact on you or the people using the site.

So you take my advice and fail validation based on some DOM manipulation that helps your users, that's great! It means you have your priorities straight. Case closed, move on with your life.

rm -rf validators/

Of course, I'm not saying to get rid of the validators entirely. They're clearly a useful tool to, at the very least, sanity check your code. Under what circumstances am I suggesting to give up on validation?

Save Time, Effort and Sanity

The short version of this is to just relax a bit. Write your markup (and your JavaScript, etc) with validation in mind. It's not a panacea, it's just a best practice. If you have to bend the rules a bit, feel more than free to do so. I promise no one will show up at your door to interrogate you, your domain isn't going to get confiscated and your cat will still sit on your lap while you code... seriously, it's OK.

You'll live longer with validation as a tool instead of as a goal.

Some social stuff: