[whatwg] 'Main Part of the Content' Idiom

Tab Atkins Jr. jackalmage at gmail.com
Fri Jun 4 13:28:31 PDT 2010


On Fri, Jun 4, 2010 at 1:16 PM, Roger Hågensen <rescator at emsai.net> wrote:
> On 2010-06-04 22:03, Tab Atkins Jr. wrote:
>>
>> On Fri, Jun 4, 2010 at 12:58 PM, Roger Hågensen<rescator at emsai.net>
>>  wrote:
>>>
>>> ...
>>> As you can see the aside is outside the body, all latest browsers seem to
>>> handle this pretty fine.
>>> http://validator.w3.org/ on the other hand gives the error " Line 12,
>>> Column
>>> 6: body start tag found but the body element is already open.<body>"
>>>
>>> Now, either that is a bug in the validator, or the body is automatic.
>>> And sure enough, removing the<body>  and</body>  tags the document
>>> validates, and none of the browsers behave differently at all.
>>> Is the body tag optional or could even be redundant in HTML5 ?
>>
>> <body>  is optional.  It automatically gets added as soon as the parser
>> sees an element that doesn't belong in the<head>.  (The<head>  is
>> optional too, as is the<html>.)  So the<aside>  triggers a<body>
>> element to be created and opened, and then later explicit<body>  tags
>> get dropped.
>>>
>>> I don't mind really, as currently I only use body to put all the "other"
>>> tags inside, so not having to use the body tag at all would be welcome,
>>> though I suspect a lot of legacy things rely on the body tag.
>>
>> No browser depends on you using the<body>  element explicitly.  It's
>> perfectly fine to write your document like this:
>>
>> <!doctype html>
>> <title>Test</title>
>> <style>
>>   aside {border:1px solid #bf0000;white-space:nowrap;}
>> </style>
>> <aside>
>>   Just testing aside outside body!
>> </aside>
>> <article>
>>   Main part of article.
>> </article>
>>
>> The<title>  and<style>  get auto-wrapped in a<head>, the<aside>  and
>> <article>  get auto-wrapped in a<body>, and the whole thing below the
>> doctype gets auto-wrapped in an<html>.
>
> Hmm! Intriguing. That is way cleaner than the "container" wrappers.
> What browsers/engines behaves like that?
> Does all HTML 4.01+ compliant browsers behave like this?

All browsers that you could possibly care about (any FF, Safari,
Chrome, Opera, or IE produced in the last decade) should act like
that.  That's why it got specified - when everyone agrees on behavior,
it's a good thing to figure that out and standardize it.  ^_^

~TJ



More information about the whatwg mailing list