Contains metadata about the document. Learn more →
<html> ElementThe <html> element is the root (top-level) element of an HTML document. Every HTML page must have exactly one <html> element that wraps all other content. It tells browsers that everything inside is HTML content and provides a place to declare the document’s primary language.
<!DOCTYPE html><html lang="language-code"> <head> <!-- Document metadata --> </head> <body> <!-- Document content --> </body></html>| Attribute | Description | Example |
|---|---|---|
lang | Specifies the primary language of the document | lang="en" |
dir | Sets the text directionality (ltr or rtl) | dir="rtl" |
xmlns | Defines the XML namespace (for XHTML) | xmlns="http://www.w3.org/1999/xhtml" |
This element supports all global attributes.
The most important use of the <html> element is declaring your document’s language. This helps browsers, search engines, and assistive technologies.
For documents with sections in different languages, set the primary language on <html> and override it on specific elements.
Use the dir attribute for languages that read right-to-left, like Arabic or Hebrew.
The <!DOCTYPE html> declaration must come before the <html> tag to ensure the browser renders in standards mode.
<!DOCTYPE html><html lang="en"> <!-- rest of document --></html>Use ISO 639-1 language codes (two-letter codes) for the lang attribute:
en - Englishes - Spanishfr - Frenchde - Germanzh - Chineseja - JapaneseFor regional variants, use the extended format:
en-US - American Englishen-GB - British Englishpt-BR - Brazilian PortugueseThe <html> element should remain simple. Avoid adding unnecessary classes, IDs, or custom data attributes here.
<!-- Good --><html lang="en">
<!-- Avoid --><html lang="en" class="no-js" data-theme="dark" id="root">The lang attribute is crucial for accessibility:
The <html> element has an implicit ARIA role of document. You typically don’t need to override this.
<!-- Implicit role, no ARIA needed --><html lang="en">| Browser | Version |
|---|---|
| Chrome | All versions |
| Firefox | All versions |
| Safari | All versions |
| Edge | All versions |
| IE | All versions |
Contains metadata about the document. Learn more →
Contains the visible content of the document. Learn more →
<!-- Avoid: Missing language declaration --><html> <body>Content</body></html>
<!-- Correct: Include lang attribute --><html lang="en"> <body>Content</body></html><!-- Wrong: Only one <html> element allowed --><html lang="en"> <body>First document</body></html><html lang="fr"> <body>Second document</body></html>
<!-- Correct: One html element per document --><html lang="en"> <body> <section>First section</section> <section lang="fr">Section en français</section> </body></html>