Reputation: 1133
I just saw some site like this:
<!doctype html>
<head>
..
</head>
<body>
</body>
There's no <html>
,is it standard?
Upvotes: 4
Views: 127
Reputation: 303244
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
.
Upvotes: 6
Reputation: 186562
They are optional/implied, however you will run into bugs in IE and possibly other browsers if you omit them so it's best to be consistent and just have them.
Additionally there are cases where you may want to hardcode classes directly on the html
element, so that's an extra reason to explicitly have it there.
Upvotes: 1
Reputation: 1173
Actually, Yes using html is a Standard. But you can do it this other way, its just not a standard. Using <!doctype html>
is a way to force the browser into standards mode. Look here for more info http://themaingate.net/dev/html/all-you-need-is-doctype-html ... In tested browsers, 100% of them were tested positively.
Upvotes: 0
Reputation: 23
It is not required, but it is strongly reccomended, and I don't see a reason why you wouldn't use it.
Upvotes: 0
Reputation: 25029
I'm pretty sure HTML5 lets you leave out a lot of tags like that; I would strongly disagree with doing so though.
Upvotes: 0