HTML <html> Tag
The <html> tag defines a document, written in an HyperText Markup Language. It includes all basic elements of an HTML document.
The <html> tag is the root element of an HTML document — it sits at the very top of the document tree and wraps every other element on the page. "Root" means it has no parent element: when the browser parses your page into the DOM (Document Object Model, the tree of nodes it builds in memory), the <html> element is the single node that all other nodes descend from. Because everything lives inside it, the <html> tag is also where you set page-wide attributes such as the document's language and text direction.
The only thing that may appear before <html> is the <!DOCTYPE> declaration, which tells the browser which version of HTML the document uses and switches it into standards mode.
The <html> element has exactly two direct children, and they must appear in this order:
- The
<head>tag, which holds metadata for the browser and search engines — the<title>,<link>,<script>, and similar tags. Nothing in<head>is shown directly on the page. - The
<body>tag, which contains everything the visitor actually sees: text, images, links, and so on.
Always set the lang attribute on <html>. It tells the browser, search engines, and assistive technology which language the page is written in. This improves indexing, helps browsers pick the right fonts and rendering for national characters, and lets screen readers choose the correct pronunciation and voice.
HTML <html> Tag with the "lang" attribute
<html lang="en">The lang attribute
The value of lang is a BCP 47 language tag — a short, standardized code for a human language. The most common form is a two-letter language subtag (from ISO 639), optionally followed by a region or script subtag separated by a hyphen.
<html lang="en"> <!-- English -->
<html lang="en-US"> <!-- English, United States -->
<html lang="fr"> <!-- French -->
<html lang="de"> <!-- German -->
<html lang="zh-Hans"> <!-- Chinese, Simplified script -->
<html lang="zh-Hant"> <!-- Chinese, Traditional script -->
<html lang="ar"> <!-- Arabic -->Set lang once on <html> to declare the document's primary language. If a section of the page is in a different language, you can override it on any inner element (for example <p lang="fr">).
The dir attribute
The dir attribute sets the base text direction of the document. It is essential for languages that read right-to-left, such as Arabic and Hebrew.
| Value | Meaning |
|---|---|
ltr | Left-to-right (the default; used for English, French, etc.) |
rtl | Right-to-left (used for Arabic, Hebrew, Persian) |
auto | Let the browser decide based on the content |
<html lang="ar" dir="rtl">Setting dir="rtl" on <html> flips the page's default alignment so text, scrollbars, and many layout features mirror correctly for right-to-left scripts.
Syntax
The <html> tag comes in pairs. All page content is written between the opening <html> tag and the closing </html> tag.
In HTML5 the closing </html> tag is technically optional — the parser can infer the end of the document. However, you should always include it. An explicit </html> keeps the document structure clear, avoids surprises when the page is processed by tooling, and is required if the page is served as XHTML.
Example of the HTML <html> tag:
HTML <html> Tag
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title of the document</title>
</head>
<body>
The content of the page
</body>
</html>Edit the example above in the editor and run it to see the result in your browser.
Attributes
| Attribute | Value | Description |
|---|---|---|
| lang | BCP 47 language tag | Declares the document's primary language (for example en, fr, zh-Hans). Recommended on every page for accessibility and SEO. |
| dir | ltr / rtl / auto | Sets the base text direction. Use rtl for right-to-left languages such as Arabic and Hebrew. |
| id | text | Assigns a unique identifier to the element, mainly used as a CSS or scripting hook. |
| xmlns | https://www.w3.org/1999/xhtml | XML namespace for the document. Required only for XHTML; ignored when the page is served as text/html, so you don't need it in HTML5. |
| manifest | URL | Pointed to an app cache manifest for offline viewing. Obsolete — removed from the standard; use service workers instead. |
The lang, dir, and id attributes above are the most commonly used ones, and <html> also accepts the full set of Global Attributes and Event Attributes.