Well-Formedness Requires Validation
Well-formed means the syntax parses; valid means the vocabulary is right — and the gap between them bites.
Well-formed means the syntax parses; valid means the vocabulary is right — and the gap between them bites.
"But it parses fine" is one of the great false comforts of web development. A document that parses is not necessarily a document that's correct, and conflating the two is how well-intentioned markup ends up quietly broken. The distinction is old, precise, and still worth getting right: well-formedness is about syntax; validity is about vocabulary.
A well-formed document obeys the grammatical rules of its markup language. Tags nest properly, attributes are quoted where required, the structure is unambiguous. In the strict XML sense, a single unclosed tag makes a document not well-formed and it simply won't parse. HTML is more forgiving — its parser is defined to recover from all sorts of malformed input — but the concept still applies: well-formedness asks whether the machine can build a consistent tree out of what you wrote.
Validity is a higher bar. A valid document is well-formed and uses only the elements and attributes the language defines, in the places they're allowed. Consider:
<ul>
<p>This paragraph is not allowed here</p>
<li>This one is fine</li>
</ul>That fragment is perfectly well-formed. Every tag opens and closes, everything nests. It is also invalid, because a <ul> may only contain <li> (plus script-supporting elements). The parser will build a tree, the page will render, and you'll never know from a glance that you broke the contract.
You might reasonably ask: if it renders, who cares? Here's who:
Well-formed says "the browser understood you." Valid says "you said something that means what you think it means."
A tired argument holds that since HTML5's parser recovers from anything, validation is pointless. That gets it backwards. Precisely because the parser will silently fix your mistakes, a validator is the only cheap way to learn you made them. Run the Nu HTML Checker over your output. Treat its errors as bugs and its warnings as code smells. You're not chasing a badge; you're catching the class of mistake that renders fine today and misbehaves in the one context you didn't test.
Well-formedness gets your document through the door. Validation confirms it's the document you meant to write. You need both, and the second one requires actually running the check.