Doesn't the file type already let the browser know that the document is an html document. MDN mentions that it is the root element, so is using it just a formality?
It is a family trait of HTML, XML, and SGML that they all need to be nested inside a root element. It's just part of the data standard and lets the interpreter know where to start and stop, and verifies that the document is complete and well-formed.
<!DOCTYPE html>
specifies the type of document. In that case it means that it is HTML 5 currently, as opposed to XML or XHTML 1.0 transitional, as examples. Keep in mind that if you are downloading these as byte streams you may not always know the file type.
Yes. The <html>
tag is the root and can even be omitted in somes cases (from MDN):
The start tag may be omitted if the first thing inside the
<html>
element is not a comment. The end tag may be omitted if the<html>
element is not immediately followed by a comment, and it contains a<body>
element either that is not empty or whose start tag is present.
But not only:
<body>
will usually be enough).lang
, which is the W3C way of defining an HTML document language.There is probably more to say but that’s what I see as arguments for the <html>
element, apart from its main role of being the root element for an HTML document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With