WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: Well formed verses Valid code


From: Jukka K. Korpela
Date: Feb 24, 2007 12:40AM

On Fri, 23 Feb 2007, <EMAIL REMOVED> wrote:

> I really didn't understand the
> difference between well formed code and valid.

"Well-formed" is XML jargon and simply means that the data constitutes an
XML document, i.e. complies with the general syntax rules of XML. This
means rules like having a matching end tag for every start tag. For
example, <foo>bar</foo> is well-formed XML whereas <foo>bar</fox> is not.

Thus, "well-formed XML document" means the same as "XML document". The
background is that people may call their files as "XML documents" loosely,
meaning that they are meant to be XML documents and look like that, even
though they may violate the syntax rules.

"Valid" is SGML and XML jargon and means that a document, in addition to
complying with general syntax rules of SGML and XML, conforms to the
specific syntax rules defined using a particular formalism called Document
Type Definition (DTD). For more on this, check

Technically, "valid HTML document" or "valid XHTML document" are
synonymous with "HTML document" and "XHTML document", since the
definitions of HTML and XHTML include a requirement on validity.

Thus, "well-formed" is relevant in XML-based contexts only, and in
describing what constitutes an XHTML document, for example, the
"well-formedness" rules are much less restrictive than "validity" rules.
"Well-formedness" operates at a low syntactic level and does not, among
other things, deal with tag and attribute names at all, except that they
contain allowable characters only.

> When I take my site
> through a validation tool like the one provided on the w3 page, am I
> getting well formed code, valid code, or both? Of course I mean when I
> get the pass.

Both, to the extent that the well-formedness concept applies (i.e., you
are using XHTML or some other XML-based language).

Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/