Is it correct to omit the html start tag in HTML5?

Question:

Should we or should we not omit the html start tag in an HTML5 document? Many developers ignore its usage. Thanks!

<!DOCTYPE html>
   <head>
      <title>...</title>
   </head>
   <body>
      <p>Tag html foi omitida!</p>
   </body>
 </html>

Answer:

Interestingly it is valid, as you can see in the w3c specification itself, the opening of the tag can be omitted as long as the first thing within the scope of the html tag is not a comment , so the example you used in the question can be considered correct, however the following would not be:

<!DOCTYPE html>
   <!-- Este HTML é inválido segundo a especificação oficial para HTML5 -->
   <head>
      <title>...</title>
   </head>
   <body>
      <p>Tag html foi omitida!</p>
   </body>
 </html>

The fact that it's valid doesn't mean you should do it, theoretically it's ok however you can't assume that all browsers implement the specification defined by w3c strictly (and in fact none of them do, they all have inconsistencies here and there), so doing so you run the risk of your HTML not rendering correctly in any of them. In the end also unless you are doing the front page of google the gain is null, you will save something like 20~ bytes of user bandwidth, this optimization is not even worth the time you spent writing the question 😉

Scroll to Top