Reputation: 25956
I know in HTML5 it is not neccessary to write <html>
tag. This is discussed in this question, regarding if it is it necessary to write head body and html tags.
But should I skip it? Is it recommended to skip? The reason I ask this is I am seeing lots of HTML5 tutorials/templates on the internet that does this in their code:
<!DOCTYPE html>
<!--[if IE 9 ]><html class="ie9"><![endif]-->
<head>
.....
Looks superfluous and completely unnecessary to me, or is it?
Upvotes: 1
Views: 270
Reputation:
The question linked in the comments answers the question if you can, and that is you can omit in the opening <html>
tag. However...
As the answers in this question and the question linked above show, the rules around when you can or cannot omit certain tags are long and lawyer-esque.
Written code isn't just for machines its for people too. This isn't to suggest that HTML should be human-readable without a browser, that's farcical, but it should be programmer-readable and there is a difference.
<!DOCTYPE HTML>
<title>Hello</title>
<p>Welcome to this example.</p>
However, without consulting the spec I am not immediately sure where each element will be in the computed DOM, for the curious its equivalent to:
<!DOCTYPE HTML>
<html><head><title>Hello</title>
</head><body><p>Welcome to this example.</p></body></html>
However, if time is at a premium (and programmer time is almost always more expensive than computing time nowadays) then knowing quite clearly what a document is doing is vital.
No doubt someone will ask, what about when space or transmission speed is at a premium. In those cases thorough profiling to determine the exact bottleneck is important, and on the fly compression, good caching of HTML, or even automated removal of elements using a library will all be vastly superior options to removing tags in source code that is to be written and interpreted by people.
Upvotes: 3
Reputation: 1170
<html>
is required for a valid HTML document only if the tag is preceded by a comment.
An html element's start tag may be omitted if the first thing inside the html element is not a comment.
See the W3C specification for details.
Upvotes: 0