Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why we use <html> tag although my website runs perfect without <html> tag

Tags:

html

tags

I need to know what is the use of <html> tag from the beginning of the webpage although website runs perfectly without these <html> </html> tags.

I knew that doctype is required but why this <html> tag is required.

like image 843
pravat231 Avatar asked Jul 17 '10 07:07

pravat231


2 Answers

The <html> tag is not required.

From the DTD:

<!ELEMENT HTML O O (%html.content;)    -- document root element -->

The two Os indicate that the start and end tags (respectively) are optional.

The element, on the other hand, is required (but the language is designed so that browsers can imply it).

Since a DOM consists of a tree of nodes, you have to have one node (the root element) for everything else to hang from, and that is the html element.

It is also a really useful place to stick a lang attribute that will apply to the entire document.

like image 54
Quentin Avatar answered Sep 22 '22 15:09

Quentin


You don't have to use it, it's optional:

7.3 The HTML element

Start tag: optional, End tag: optional

Source: http://www.w3.org/TR/html401/struct/global.html#h-7.3

like image 41
Anax Avatar answered Sep 21 '22 15:09

Anax