HTML Reference Β· Document and Metadata
The <html> element
Reference for the HTML <html> element: the root of every document, why the lang attribute matters, the dir attribute, examples and technical details.
The <html> element is the root of an HTML document: every other element sits inside it. It contains exactly two children, <head> followed by <body>, and it is the right place to declare the language of the whole page.
HTML
<!doctype html> <html lang="en"> <head>β¦</head> <body>β¦</body> </html>
Try it
Attributes
| Attribute | Values | Description |
|---|---|---|
lang |
A language tag, such as en, en-GB or pt-BR |
A global attribute, but most important here: it sets the default language for the whole document. |
dir |
ltr, rtl, auto |
A global attribute that sets the base text direction. Use rtl for Arabic, Hebrew, Persian and other right-to-left pages. |
xmlns |
http://www.w3.org/1999/xhtml |
Allowed for compatibility with XHTML, but has no effect in HTML documents. |
It accepts all other global attributes. The manifest attribute belonged to the removed Application Cache feature and is obsolete.
Usage notes
- Always set
lang. Screen readers pick their pronunciation rules from it, browsers use it for translation offers, hyphenation and font choice, and search engines use it as a hint. Mark passages in another language with their ownlang, as in the example. Valid codes are listed in Language codes. - Write the doctype first.
<!doctype html>goes before<html>and keeps the browser in standards mode. See Doctypes. - The tags are optional, the element is not. The parser always creates an
<html>element, even if you leave out its tags. Writing them out is the usual style, mostly so you have a place forlang; see the HTML Style Guide. - Styling the root. In CSS,
:rootandhtmlselect this element. Root-level font sizes (remunits) and custom properties are usually set here. document.documentElementgives scripts direct access to this element.
Technical summary
| Content categories | None |
| Permitted content | One <head> element followed by one <body> element |
| Tag omission | The start tag may be omitted if the first thing inside it is not a comment. The end tag may be omitted if it is not immediately followed by a comment. |
| Permitted parents | None; it is the root of the document (or of a subdocument fragment) |
| Implicit ARIA role | document |
| DOM interface | HTMLHtmlElement |
| Default display | block |
Browser support
Supported in every browser.
Related
<head>β the metadata container<body>β the visible content- Global attributes β
lang,dirand the rest - Lessons: Your First Web Page, Elements and Tags, Accessibility Basics