Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to have <html> at all?

Tags:

html

I just saw some site like this:

<!doctype html>
<head>
..
</head>
<body>
</body>

There's no <html>,is it standard?

like image 767
yoyo Avatar asked Feb 25 '23 08:02

yoyo


1 Answers

As you can see from the specs, HTML 4 has long allowed the html, head, and body tags to all be optional.

The HTML5 spec (whose DOCTYPE you observe in your sample) also says:

An html element’s start tag may be omitted if the first thing inside the html element is not a comment. An html element’s end tag may be omitted if the html element is not immediately followed by a comment and the element contains a body element that is either not empty or whose start tag has not been omitted.

So, if by "is it standard?" you mean, "is this legal according to standards?", the answer is "Yes".

But if by "is it standard?" you mean, "is it commonplace?", then the answer is: "No, you will find that most web pages in the vast sea of the Internet tend to be wrapped in <html> elements.

Note that this is not the case for XHTML. From the specs:

The root element of the document must be html.

like image 74
Phrogz Avatar answered Apr 03 '23 19:04

Phrogz