So far, I've been using this as base for all my (very simple) webpages:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Example page</title>
</head>
<body>

<p>Some content</p>

</body>
</html>

But recently I found out that HTML treats the <html> and <body> tags as "optional", and though to write pages like this:

<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Example page</title>
</head>

<p>Some content</p>

Is the latter form valid HTML 5? Can it cause any trouble with some browsers?

2 answers

o.k.w 2355
1
point
This was chosen as the best answer

Yes, the latter is valid HTML5. Check it at W3C validator. I cannot be sure if it is compliant with the existing browsers considering HTML5 is yet to be confirmed and supported fully across modern browsers.

My hunch is it should work.

Answered about 9 years ago by o.k.w
0
points

You might want to note that in HTML5 all body-specific attributes were removed. As O.k.w. mentioned, the latter is indeed valid HTML5.

However, in HTML5 is still good semantic markup, so even if you don't have to, in most cases it's probably a decent idea, anyway.

Answered about 9 years ago by Anthony Lemmer