Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The space character restriction to make </head> optional

Tags:

html

The HTML5 reference states:

A head element's end tag may be omitted if the head element is not immediately followed by a space character or a comment.

What does this "space character" restriction mean? I can only think that something like

<title>My Page</title><p>Some stuff.</p>

is valid, while

<title>My Page</title>
<p>Some stuff.</p>

is not, as the implicit </head><body> tags would not surround a newline. But I feel I'm off the mark. A clarifying example will be greatly appreciated.

Thanks to all!

like image 789
ezequiel-garzon Avatar asked May 29 '12 13:05

ezequiel-garzon


2 Answers

It just means that since comments and space characters may appear inside the head element, they will not implicitly end the head element.

So if you want want the comment (for example) after the head element is closed and not just before it is closed, then you have to use an explicit </head>

i.e.

</title> <!-- foo --> <body>

means the same as

</title> <!-- foo --> </head><body>

and there is no way to represent

</title></head> <!-- foo --> <body>

without using an explicit </head>

like image 196
Quentin Avatar answered Oct 12 '22 07:10

Quentin


The documentation is referring to the other end of the element (where </head> would normally go).

For example:

<head>
    <title>Hello World</title>
<body>
...

is okay, but this apparently is not:

<head>
    <title>Hello World</title>
  <body>

Nor is this:

<head>
    <title>Hello World</title>
<!-- This is a comment -->

However (and this is a big however), you should never do this. It leads to confusing code, may supported poorly by some browsers, and may be invalid in future version of HTML. Keep it clean and stable by using good, readable markup.

like image 30
George Cummins Avatar answered Oct 12 '22 08:10

George Cummins