About the <html> tag


If at the beginning of the HTML files, we have already put !DOCTYPE html to declare to the browser about the language and version of HTML that we’re gonna use. Then why do we have to add the html tag later on, so that anything between the opening and closing html tag will be interpreted as HTML code? Isn’t the declaration at first was enough?
And is that possible that after the !DOCTYPE html declaration, we can use not only HTML code but also other code?


We need a root element.


<!DOCTYPE html> tells the browser of language and version we are going to use

then we need <html></html> is the top level element (also known as root element). Having a top level element is very useful in GUI programming


No, that IS the top level element, but it is indicated in,

<!doctype html>

This is the declaration that assigns the root element, ‘html’.


I am not sure if I just mis-read but…

Does that mean we do not need necessarily?
since the top level element is indicated within <!doctype html>?

if that is the case then what is the purpose of when it is indicated by <!doctype html> already?


That would be the operative phrase. <html></html> IS the root element, not the indicator. The document type declaration specifies <html></html> as the document root. Recall that in SGML there are many doctypes. We’re narrowing that down to one. Modern browsers will interpret this as Living Standard. We will likely know it as HTML5.