What are the advantages and disadvantages (if any) of making sure that all pages validate compared to having non-valid HTML that however works on all major browsers?
Webmasters Stack Exchange is a question and answer site for pro webmasters. It only takes a minute to sign up.Sign up to join this community
I think it's definitely worth doing, but you should never be a slave to validation -- it's a fool's game.
Validate your HTML. Know what it means to have valid HTML markup. Understand the tooling. More information is always better than less information. Why fly blind?
Nobody cares if your HTML is valid. Except you. If you want to. Don't think for a second that producing perfectly valid HTML is more important than running your website, delivering features that delight your users, or getting the job done.
I consider valid HTML a worthwhile goal, but do not see it as the be-all and end-all of building good websites.
The trick is, your markup may be perfectly valid, yet it may not be semantic - e.g. using tables for layout or navigation. There's a difference between valid code and semantic code.
On another note, if you use advertising or external scripts, they may insert their own markup which has a chance to really mess with your own.
The big plus of valid HTML is that your page is then more accessible to things other than "major browsers". All of the "major browsers" have endless workarounds to deal with all the invalid junk which populates the WWW. However, sticking to valid HTML helps, for example, if someone is using a browser for the visually impaired, or accessing your pages off-line, etc.
Validation in of itself isn't so critical, since few browsers are 100% compliant and the spec isn't 100% clear on how to interpret the rules.
However being valid HTML puts you in a better position to adapt and improve your site. As the standards move, they will typically migrate forward and if you new site is valid, then updating to support the latest thing should be easier.
Bottom, being valid makes it easier to stay on top of the game and be as compatible as possible with the widest audience.
The best approach is to learn which invalid HTML is bad, and which invalid HTML does not matter.
For example, forgetting to close a
<div> tag is very bad, because your layout will almost certainly screw up in one or more browsers.
<br> instead of
<br /> in XHTML does not matter - all browsers will interpret both as a line break without problems. Using the
target attribute on links is invalid, but the worst case scenario is that the browser doesn't open the link in a new window.
When running the validator, you'll need to examine the errors it gives you on a case-by-case basis. Is validation important? To me, yes, it's very important. But is it a requirement? No.
When validating, do not just assume that if you have errors you're doing it wrong. Semantics are vastly more important, and it just so happens that valid HTML is more-often-than-not the natural result of having proper semantics.
One reason to test your site for valid HTML is that it ensures that the search engine spiders will be able to fully index and determine the meaning of your pages. If they cannot do so due to malformed HTML (which the major browsers may work around for historical reasons) then you are potentially limiting your search engine rankings.
There has also been speculation that while the major search engines do a good job of dealing with malformed HTML, they may also assign page quality "points" for validity, further affecting your ability to rank as high as your content deserves.
I really don't think it matters anymore. I used to be a slave to validation, now I rarely ever check it. Perhaps I got burned out from making sure my site was valid, or perhaps I just didn't care anymore because nobody else will. I can guarantee 99.9% of our visitors don't even know what it is as well as even care if they did. Future browser software might, but when that day comes, I'll worry about it then.
there is no disadvantage of having valid html. there is a reason why there is a spec in the first place and why a lot of effort is being put into the spec to define how things should work.
basically, all you gain is to meet the specs. which in turn means, programs written to read html (browsers, bots) can not blame YOU for not meeting the specs if something goes wrong. and some of these programs give you extrapoints (higher ranking in search engines if the bot reports "meets the spec"). if you meet the specs you will be caught much less by surprise if some browsers do not render broken html the way you think it should.
so, to meet the specs and write valid html is good for you, no disadvantages at all.
id more than once), and issues for some users (e.g. not including a meaningful or blank
alt attribute on images).
If all our pages validate, that’s a nice automated check you can do to rule out sources of errors. If you leave some validation errors in because you know they’re not causing any harm, your check is no longer automated: you have to look at each error, and remember that it’s okay. Personally, I prefer it when computers reduce the amount of work I have to do rather than increase it.
One point no one's mentioned is future browser developments. Though all today's browsers handle invalid markup relatively well, that may not always be the case.
Browser makers in the future will be ensuring their browsers work to HTML/XHTML standards, so this is what web developers should be hitting as well. Just because a particular bit of invalid markup works now doesn't guarantee it will work in future browsers.
Validity helps you avoid incompatibilities and helps keep code maintainable. Browsers recover from markup errors, but sometimes in very unintuitive ways.
DTD-based (HTML4, XHTML1 @ W3C) — Might not be worth it. DTD is primitive and, e.g., cannot check validity of most attributes. You'll mostly get hard to understand errors about entities and nesting.
HTML5 validator — Yes. Definitely. HTML5 is more pragmatic and allows some harmless constructs that used to be errors. OTOH Henri's validator is much more thorough and better at discovering real problems.
Validity of JS-generated code might matter, as browsers operate on DOM, regardless how it was created. If you use
document.write(), then you even have to take care to get syntax correct (it goes through same parser as page source).
Even if your HTML works on all major browsers, it's still worth doing as it sometimes can cause problems with search engine crawlers like googlebot. For example see this:
Google and Bing do not, have not and will never use CSS or HTML validation as a ranking factor.
The majority of websites have dozens to hundreds of errors and you need not worry about them because all search engines care about is how the page renders. Just ensure your website renders correctly in all major browsers and Google's Fetch.