HTML <html> Element

The HTML <html> element represents the root of an HTML document and contains all other HTML elements except the <!doctype> declaration. It normally contains a <head> element for document metadata and a <body> element for the page content.

Syntax

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Page Title</title>
  </head>
  <body>

    <h1>Page Heading</h1>
    <p>Page content goes here.</p>

  </body>
</html>

The <html> element requires an opening and closing tag and surrounds the document's <head> and <body> elements. The <!doctype html> declaration appears before the opening <html> tag and is not contained inside it.

Attributes

The <html> element supports the global HTML attributes and the following element-specific attribute:

Attribute Description
xmlns Specifies the XML namespace for the document. In documents served as HTML, this attribute is optional and, when used, its value must be http://www.w3.org/1999/xhtml.

Example

This example shows the <html> element surrounding a complete basic HTML document. The lang global attribute identifies the primary language of the document as English.

Play in Editor

Usage Notes

The <html> element is the document's root element. All HTML elements in the document are descendants of it except for the <!doctype> declaration, which appears before the element.

An HTML document normally contains one <html> element with a <head> followed by a <body>.

Add the global lang attribute to the <html> element to identify the primary language of the document. For example, <html lang="en"> identifies the document as English.

The <html> element should not be confused with the <!doctype html> declaration. The doctype tells the browser to process the document using modern HTML standards, while the <html> element contains the HTML document itself.

Although HTML syntax allows the opening and closing <html> tags to be omitted under certain conditions, including them explicitly makes the document structure easier to recognize and understand.

Accessibility

Specify the document's primary language with the lang attribute on the <html> element. This information helps screen readers and other assistive technologies use the appropriate pronunciation and language rules when interpreting the page.

If part of the page uses a different language, apply an appropriate lang attribute to the element containing that content rather than changing the document's primary language.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

For detailed browser compatibility information, see Can I Use: HTML <html> Element .

<!doctype> - Declares the document type and tells browsers to process the page using modern HTML standards.

<head> - Contains metadata and resources that provide information about the HTML document.

<body> - Contains the document content displayed as part of the web page.

Specifications

HTML Living Standard: The <html> Element