Web Devout tidings

Don’t believe everything the Validator tells you

The W3C Markup Validator is an excellent tool. If you’re a serious web developer, using the Validator is probably a routine by now. It’s also very reliable when it says you have an error. However, there are plenty of cases where the Validator will say a page is valid even though it doesn’t actually comply with the HTML or XHTML standard.

The Validator pretty much assesses two levels of compliance: it makes sure that your document is parseable using either an SGML parser (for HTML) or an XML parser (for XHTML), and then it checks your document’s compliance with the DTD specified by the doctype declaration.

However, the HTML and XHTML specifications demand additional restrictions that aren’t part of the DTD. For example, many values are specified as “number” values, even though in the DTD they are ultimately just CDATA, which can contain text. XHTML further limits the Validator due to the fact that XML DTDs aren’t as expressive as other DTDs and are unable to tell the Validator that, for example, form elements cannot be descendants of other form elements.

Here are a few test cases having fun with non-compliant but “valid” markup:

2 Responses to “Don’t believe everything the Validator tells you”

  1. Mitch 74 Says:

    To be fair, the two latest examples can be detected by Firefox (at least) switching off Strict mode into Quirks mode.
    About the id =/= name, due to inconsistencies in both the specs and UAs, it’s best to always duplicate id and name where relevant/possible anyway.
    The attributes types could be justified this way: currently decimals are used, what happens the day we switch to another system? Say, one where zones appear on a different media – like, say, “brainreader-wavelength 900″? Or, more realistically, “BraillePanel:20″

    For the unstackable stacked nodes though, well, this kind of mistakes hints at an error in the CMS – or PEBCAK.

    Posted using Mozilla Firefox 3.0 on Linux.

  2. Flüge Says:

    I always kept something like this in mind, now I know it’s true. Thanks for the examples.

    Posted using Mozilla Firefox 3.0.3 on Windows.