Search code examples
htmlmetadatastylesheetspecifications

What purpose do the meta, link and style elements have within a document's body?


The HTML4.01 specification states quite clearly:

Unlike a, [the link element] may only appear in the head section of a document...

HTML4.01 Specification - 12.3 Document relationships: the link element

It also goes on to say roughly the same thing about the meta and style elements.

However the HTML5 specification states:

A body element's start tag may be omitted if the element is empty, or if the first thing inside the body element is not a space character or a comment, except if the first thing inside the body element is a meta, link, script, style, or template element.

HTML5 Specification - 4.3.1 The body element

It doesn't appear to go on to explain why the meta, link and style elements are suddenly allowed to be contained within the body element; especially not as the very first element.

It does give a couple of examples of usages with the style and link elements, but it doesn't explain them very well. For example, one example featuring the link element it gives this:

<header>
  <h1 itemprop="headline">The Very First Rule of Life</h1>
  <p><time itemprop="datePublished" datetime="2009-10-09">3 days ago</time></p>
  <link itemprop="url" href="?comments=0">
</header>

It doesn't explain why the link element would be used here instead of a - nor does the Microdata Working Group Note which appears to define the itemprop attribute.

What's going on here? Why are these elements suddenly allowed within the body (and somewhat importantly as the first child)?


Solution

  • It doesn't appear to go on to explain why the meta, link and style elements are suddenly allowed to be contained within the body element

    This seems to be left over from some proposals that didn't make it into HTML 5.

    See HTML 5.1 which allows those elements in flow content and expands their definitions to describe what they do when they appear in the body.

    especially not as the very first element.

    The significance of being the first element only relates to the tag omission rules.

    Given:

    <head …>
        <title>
    <h1>
    

    It is clear that the h1 ends the head element and starts the body element because h1 cannot appear in the head.

    Given:

    <head …>
        <title>
    <meta>
    <h1>
    

    You can't apply the same rule to <meta> because it can appear in the head or the body.