Re: W3C validator disallows the <pre> tag

On Mon, 26 Jan 2004, Matitiahu Allouche wrote:

> In a file that I submitted for validation, the W3C Validator flagged the
> <pre> tag with the following message:
>
> document type does not allow element "PRE" here; missing one of "APPLET",
> "OBJECT", "MAP", "IFRAME", "BUTTON" start-tag

The important word is "here". The element occurs in a context where it
is not allowed. For example, <font ...><pre> is not allowed, since
a <font> element must not contain a <pre> element.

(As usual, posting the URL would have helped to pinpoint the specific
problem.)

> This tag is defined in section 9.3.4 of the 4.01 HTML specification, where
> it does not seem to be related to applet, object, iframe or button tags.

It is defined there and contained in all DOCTYPEs, but the content models
of other elements define the contexts where the <pre> element may appear.

The reference to "APPLET" etc. has confused many people, and it probably
results from the internals of the validator's parser. The parser's error
reporting tries to be clever: after noticing <pre> inside <font> for
example, it analyzes what _intervening_ markup might possibly make
the document valid, and e.g. <font ...><applet ...><pre>...</pre>
</applet></font> would be valid. This does not, of course, imply that it
would make sense, or even be correct by HTML specifications.

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

Received on Monday, 26 January 2004 05:20:07 UTC