If you find this helpful, please click the Google Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.) |
The <html> tag for HTML 5
The <html xmlns="http://www.w3.org/1999/xhtml"> tag includes the HTML namespace declaration.
The <html>
tag is the tag for the top element of an HTML document. The parent of the html
element is the root node of the DOM.
Inside the html element is the head element and the body element. One purpose of these elements is to separate the page title and other metadata information in the head section from the actual visible content of the document in the body section.
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
The <html> tag includes an xmlns attribute that specifies the HTML namespace assigned in 1999 for the year 2000 and later versions of HTML. Namespace partitions are needed to avoid naming collisions for element types in a schema (or DTD), especially if it can be used for content that may be integrated or aggregated with other content. Element types with the same name in different namespaces have completely separate definitions.
It is important for element names to be associated with the correct namespace when tags are being processed by a parser or script, using the Document Object Model or CSS for example, so the element is interpreted as the correct element type. If an element is interpreted using the wrong element type definition, the attributes and child elements will not properly match up with the element's properties and content model. (See the difference between attributes and properties if those terms are unclear.)
The HTML elements will be in the http://www.w3.org/1999/xhtml namespace by default in documents that are being parsed as HTML, so the xmlns attribute is optional ... in that case only. When the document is being parsed as xHTML, the XHTML-compatible serialization of HTML, or as pure XML, however, the xmlns attribute is required. Therefore, it is recommended that xmlns="http://www.w3.org/1999/xhtml"
should always be included on the <html> tag, since it is the parser that determines how to interpret a document.
When HTML Is Parsed As | xmlns required? |
---|---|
HTML | No it is assumed |
xHTML | Yes, it is required |
Pure XML | Yes, it is required |
See the HTML Namespace Tutorial for more information on namespaces in HTML.
<html> Tag Syntax
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet ...?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ... metadata content ... <title>My Title</title> ... metadata content ... </head> <body> ... flow content ... </body> </html>
Rules for coding the html element for HTML 5
Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.
- Code the <html> tag after the HTML DOCTYPE declaration at the beginning of the HTML document. To put common elements in templates that can be cached by browsers to speed up page load times, optionally include an xml-stylesheet instruction before the <html> tag.
- The tag's element type name is
html
. The name uses lower case letters and should be in the HTML namespace. - Indicate the namespace and HTML version by coding an xmlns attribute with a value of
"http://www.w3.org/1999/xhtml"
enclosed in double quotes. (For backward compatibility, the namespace from the 1999 W3C standard is used for all HTML versions from that year forward, including XHTML and HTML 5.) Aversion
attribute should not be coded. - Code a matching
</html>
end tag at the end of the document. - Between the starting
<html>
tag and ending</html>
tag, include a head element consisting of a starting <head> tag and ending </head> tag and a body element consisting of a starting <body> tag and ending </body> tag.
<html> Content Model
Contents of the <html> Tag
The html element typically contains the following child elements:
- a head element with metadata about the HTML document, and
- a body element with the content of the web page
possibly interspersed with HTML comments.
<html> Tag Attributes
Attributes of the <html> tag
global attributes | In addition to the local attributes of the <html> tag below, any of the common HTML attributes can also be coded. |
xmlns |
The xmlns attribute is used to declare the namespace URIs and associated prefixes for various namespaces in HTML documents, such as:
See the HTML Namespace Tutorial for more information on namespaces in HTML. |
manifest |
a URI reference that resolves to the URL of an application cache manifest, a list of files that can be cached for offline use For example: index.html<html xmlns="http://www.w3.org/1999/xhtml" manifest="/cache.manifest">cache.manifest # http://www.ExampleOnly.com/cache.manifest CACHE MANIFEST NETWORK: * CACHE: /index.html /styles/style-sheet-screen.css /styles/style-sheet-handheld.css FALLBACK: / /offline.html The browser may prompt the user for permission to store the offline content, such as in Firefox: |
version |
The version attribute has been deprecated. Use the xmlns attribute instead. |
<html> Tag Examples
Examples of the html
tag in HTML 5
This is how the <html> tag should be used:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Example Only</title> ... </head> <body> ... </body> </html>
The <html> tag should always include an xmlns
attribute, which explicitly specifies the namespace of the HTML elements in the document. See the Changes below for more details. Additional namespaces, such as for MathML or RDF could also be included at this level.
Any HTML element, including the html element may also specify the language using the global lang attribute and, optionally, the global xml:lang attribute. The xml:lang attribute may be specified only if the lang attribute is also included.
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
Changes in HTML 5 - <html> Tag
What's new in HTML 5
In addition to the xmlns
attribute for the HTML namespace, the <html> tag may specify prefixes for other element namespaces, such as for SVG tags or MathML tags.
The manifest attribute has been added.
Differences between HTML 5 and earlier versions of HTML
In the year 2000 the xmlns
attribute was introduced in Recommendations from the W3C HTML Working Group to specify the namespace of the HTML elements. However, many documents on the web are still coded without it and therefore may fall back to the older 1997 HTML version 4 standard, so going forward you should make sure that the <html> tag in any HTML pages include the xmlns
attribute.
For 2000 W3C HTML, HTML 5 and later, the <html> tag should be coded like this:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> ... </html>
In addition to being required by the 2000 W3C standard, specifying the namespace for the elements in the document using the xmlns
attribute allows the documents, or a subset of nodes in the document, to be aggregated with other content. If the namespace for the elements is not specified, a reader of a combined documents created by an aggregator will be unable to distinguish the elements in one namespace from those in another. This is the biggest limitation of RSS 0.92 version 2.0 although RSS version 1.0 does use namespaces to solve the issue.
The following attributes should not be coded on the <html> tag because they either have been deprecated or were never officially supported:
version
- use thexmlns
attribute described above instead