html – document root

<html lang="en">…</html>

The root element of the document: everything except the doctype is inside it. It contains exactly two parts – the head (head) and the body (body). Its most important attribute is lang with the language of the page.

  • Default display: display: block
  • End tag: can be omitted – just like the start tag; the browser adds the element itself
  • Content: one head element followed by one body
  • Where it can be used: the root of the document, right after the doctype
  • DOM interface: HTMLHtmlElement

Attributes

  • lang – the language of the page content (en, en-GB, fr, de-AT…). It applies to the whole page; a part in another language gets its own lang.
  • dir – text direction: ltr (left to right, the default), rtl for Arabic or Hebrew.
  • Obsolete: manifest (offline applications via AppCache – browsers removed it), version. xmlns is unnecessary in HTML.

Examples

The root with the language of the page:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Contact – Mill Lane Bakery</title>
  <link rel="stylesheet" href="/css/styles.css">
</head>
<body>
  <h1>Contact</h1>
  <p>Open daily from 6 am to 6 pm.</p>
</body>
</html>

Without the html, head and body tags – valid HTML, the browser adds all three elements. In practice they are written for readability:

<!DOCTYPE html>
<meta charset="utf-8">
<title>The shortest valid page</title>
<p>This paragraph ends up in the body even though there is no body here.</p>

Accessibility

Screen readers choose the voice and pronunciation rules according to lang – without it they may read a French text with English pronunciation. The browser uses the language too: it offers to translate the page and chooses the dictionary for spell checking and the hyphenation rules (hyphens: auto).

Things to watch out for

  • Without lang, CSS does not hyphenate words (hyphens: auto) and the browser may offer to translate the page as if it were in a foreign language.
  • The value is a BCP 47 language tag (en, en-GB), not a country code – lang="uk" means Ukrainian, British English is en-GB.
  • The browser always adds omitted tags, so document.documentElement, document.head and document.body exist even in a page without them.

Browser support

Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 1. As of October 2026 (MDN browser-compat-data).

Related:
doctype – document type
head – document head
body – page body
lang – language (attribute)
dir – text direction (attribute)