Do I need to have <html> at all?

I just saw a site like this:

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

No <html> , is this standard?

+4
source share
5 answers

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

The HTML5 specification (whose DOCTYPE you see in your example) also says :

The start tag for html elements may be omitted if the first thing inside the html element is not a comment. The end tag of html elements can be omitted if, right after the html element, the comment is not marked with a comment, and the element contains a body element that is either not empty or its start tag has not been omitted.

So, if "standard"? you mean: “Is it legal according to standards?”, the answer is “Yes.”

But if "standard?" you say: “Is this a common thing?”, then the answer: “No, you will find that most web pages in the vast sea of ​​the Internet are usually wrapped in <html> elements.

Please note that this does not apply to XHTML. From the specification :

The root element of the document must be html .

+6
source

They are optional / implied, however you will encounter bugs in IE and possibly other browsers if you omit them so that it is better to be consistent and just have them.

In addition, there are times when you may want to hard code the classes directly in the html element, so that there is an extra reason to explicitly specify it there.

+2
source

I'm sure HTML5 allows you to leave a lot of such tags; I would strongly disagree with this, though.

0
source

In fact, using html is the standard. But you can do it differently, it's just not the standard. Using <!doctype html> is a way to get the browser to work in standard mode. See http://themaingate.net/dev/html/all-you-need-is-doctype-html for more information ... In tested browsers, 100% of them were tested positively.

0
source

This is not required, but it is highly recommended, and I see no reason why you did not use it.

0
source

Source: https://habr.com/ru/post/1335793/


All Articles