<html> tag in HTML


<html> in HTML is the parent tag, that contains each and every element tags of the HTML document inside of it, except for the <!DOCTYPE> tag. It is also known as the root element. You can only use one pair of <html> opening and closing tags.

  • Categories: None.
  • Contexts in which this element can be used: As the document's document element.
    Wherever a subdocument framework is allowed in a compound document.
  • Content model: A <head> element followed by a <body> element.
  • Tag omission in text/html: The start tag can be omited, if the first thing inside the <html> element is not a comment.
    The end tag can be omited too, if the <html> element is not immediately followed by a comment.
  • Content attributes: Global attributes.
    manifest - Application cache manifest (Depreciated later)
  • Allowed ARIA role attribute values: None
  • Allowed ARIA state and property attributes: None
  • DOM Interface: interface HTMLHtmlElement:HTMLElement{};

Note:
For more details, please refer the spec reference given below, in the Source heading.

Syntax

<html>
    <!--content of the html page-->
</html>

Note:
The contents inside of the <html> tag can only be <head> and <body> tag.
<!DOCTYPE> is always outside of the <html> container.

Use of the <html> tag

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Welcome to OpenGenus!!</title>
    </head>
        
    <body>
        <h3>Hello there!!</h3>
        <p>This is a sample paragraph!!</p>
    </body>
</html>

Browser support

Note:
Since this is an essential part of the HTML document, every browser will support the <html> tag by default.

Elements Chrome Firefox Opera Safari
<html> Yes Yes Yes Yes

Attributes

Note:
<html> tag also supports the global attributes.

  • manifest * - Has the URI of the .appcache file, which has the list of files that should be cached locally, for offline use. It's use has been discouraged, and instead, replaced with service workers.
<html manifest="/demo.appcache">
    ...
</html>
  • version * - Specifies about the version of the HTML, that is being used. Has been replaced with the <!DOCTYPE> tag.
<html version="2.0">
    ...
</html>

Warning!:
Don't use this tag, by any means! This attribute is very much outdated, and has only been added for the sake of understanding. It has been removed from almost every browser, from the version 4.01 specification. Use <!DOCTYPE> for specifying the version of the HTML document.

  • xmlns - This attribute is used to define the namespace for the XML of the given document. This is a must for documents that parse with XML parsers, and is optional for text/html documents. The default value is http://www.w3.org/1999/xhtml. Do note that this is only if you want to conform to XHTML standards.
<html xmlns="http://www.w3.org/1999/xhtml">
    ...
</html>

* these attributes are not supported/ to be removed by any major browsers.

Note:
Use of lang attribute is encouraged for identifying the language, and thus, this can help the screen readers to determine the proper language to speak in.
Failure to do so may result in mispronunciation.
This also makes sure that the metadata, like <head>, or <title> is announced properly.

CSS default properties

html {
  display: block;
}

Note:
This can vary for different browsers. To check the exact default attributes, create an HTML file with just the <!DOCTYPE> and <html> tags, and execute it in the preferred browser. Then, proceed to the developer tools(F12 is the universal shortcut for any desktop browser, but there are other shortcuts like Ctrl + Shift + I on Windows or Cmd + Opt + I on Mac), and check the properties of the tag.
This same method can be tried on any other tags too, but care must be taken that no CSS properties (including inline, internal and external types) are added.
The <head> and <body> tags were added automatically in this document, you can ignore them.
Warning!:
Do remember that tags can inherit properties, and so it would be in the best to define a tag without the outer parent element!!
Screenshot--24--1

Question 1 :

Does the <html> tag contain the <!DOCTYPE> tag within itself?

No
Yes
Could be placed anywhere
This is just a made up word
The <!DOCTYPE> is the only element that is not a part of the <html> tag. The <html> tag will contain every tag, other than the <!DOCTYPE> tag.

Question 2 :

Why is the lang attribute recommended?

To help screen readers pronounce properly
Because this attribute is compulsory, according to the new HTML 5 spec
It is how the syntax is
All of the above
This is not a hard-coded feature, but for the sake for making it friendly for people who have to use screen readers, lang attribute must be placed, followed by the language that the webpage is using.

Question 3 :

What was the version attribute replaced with?

It was not replaced, it was removed instead
Nothing - the version attribute is still supported
<!DOCTYPE>
The version attribute was instead added!
The version attribute was not replaced with the <!DOCTYPE>! It used to exist alongside with the <!DOCTYPE> tag, until it was removed finally from version 4.01.

Question 4 :

Can we create an HTML document without the <html> tag?

Yes, but care must be taken about the comments
No, this won't be a valid HTML document
There is no such thing as <html> tag in the new version
It is compulsory to add <html> tag
Athough it is okay to avoid <html> tag, but it comes with restrictions that states that the content as a whole inside should not be started, or ended with comments. They can, however, be in between the document content.

Question 5 :

Can we create an HTML document with multiple <html> tag?

No, HTML supports only one <html>
We can create multiple <html> tags, but it should be avoided, to reduce complexity
Absolutely!
Yes, but they should both have proper closing tags
There can only be one <html> tag!! None of the other options are correct!!

Question 6 :

What is the use of the manifest attribute?

This tag has been depreciated, and use of service workers is recommended
To cache the files inside the ".appcache" locally
There isn't any such attribute
This is implicitly declared, hence no need to write again
The use of the manifest attribute was to store files locally, so that the web application can be accessed even without a network connection

Further reading