[whatwg] 'Main Part of the Content' Idiom
Tab Atkins Jr.
jackalmage at gmail.com
Fri Jun 4 13:03:11 PDT 2010
On Fri, Jun 4, 2010 at 12:58 PM, Roger Hågensen <rescator at emsai.net> wrote:
> On 2010-06-04 18:39, Daniel Persson wrote:
>
> I am not advocating ad-tags. The idea of globally structuring content on the
> web is very appealing, it would make it easier for a lot of things and a lot
> of people. Let's do it!
> ...but I can't see it happening where <body> would be main content + ads +
> anything there is not a sensible tag for + anything a
> lazy/stressed/unconscious author didn't tag otherwise. Let's just have a
> main content tag or a strong main content strategy.
>
>
> Hmm! It is a valid point actually.
> Oh and here is some food for though. This works in all latest browsers.
> Opera and Firefox have same behavior, while Chrome is a tad different, and
> as IE is unable to style unknown tags sadly.
>
> <!doctype html>
> <html>
> <head>
> <title>Test</title>
> <style>
> aside {border:1px solid #bf0000;white-space:nowrap;}
> </style>
> </head>
> <aside>
> Just testing aside outside body!
> </aside>
> <body>
> <article>
> Main part of article.
> </article>
> </body>
> </html>
>
> 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>.
~TJ
More information about the whatwg
mailing list