The <html> Element
As defined in the HTML Living Standard, the <html> element represents the root of an HTML document. All other elements (except for the <!DOCTYPE>) must be descendants of this element.
<html lang="en">
<head>...</head>
<body>...</body>
</html>
While often called the "root element," it is technically the container for the entire document structure.
View HTML Living Standard: The html elementThe Most Critical Attribute: lang
The lang attribute specifies the primary language of the document. This is not just a hint for search engines; it is a vital accessibility requirement.
WCAG Requirement: Language of Page
Success Criterion 3.1.1 (Level A): The default human language of each Web page can be programmatically determined.
When a screen reader encounters a page without a lang attribute, it defaults to the user's system language. If the website is in French but the user's system is in English, the screen reader will attempt to read the French text using English pronunciation rules, resulting in unintelligible speech. Declaring the language on the <html> tag prevents this failure.
Technical Requirements
- Singleton: There must only be one
<html>element per document. - Namespaces: In XHTML, the
xmlnsattribute is required. In standard HTML5, it is optional but often included for compatibility (e.g.,xmlns="http://www.w3.org/1999/xhtml"). - Placement: It must follow the
<!DOCTYPE html>declaration.
A11y Tip: Beyond the Root
While the root lang attribute sets the default, you should use the lang attribute on any element if the language of that specific section changes (e.g., a quote in another language). This satisfies WCAG SC 3.1.2 (Language of Parts).