HTML Tags
HTML <html> Tag
The <html> tag is the root element that wraps all other elements on the page and represents the whole document. Everything except the doctype lives inside it.
The <html> Tag
The <html> element is the top-level element of an HTML document, often called the root element. Every other element must be a descendant of it. A document contains exactly one <html> element, which itself contains one <head> followed by one <body>.
It has no visible rendering of its own, but the lang attribute you set on it is used by search engines, screen readers, and translation tools to identify the page's language.
Syntax
<html lang="en">
<head> ... </head>
<body> ... </body>
</html>Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Language Example</title>
</head>
<body>
<h1>Bonjour et Hello</h1>
<p>This page declares English as its language.</p>
</body>
</html>More Examples
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Exemple</title>
</head>
<body>
<h1>Bienvenue</h1>
<p>Cette page est en francais.</p>
</body>
</html>Attributes
| Attribute | Description |
|---|---|
| lang | Declares the primary language of the document (for example en, fr, hi). |
| dir | Sets base text direction: ltr, rtl, or auto. |
| xmlns | The XML namespace, used mainly when serving XHTML. |
Always set a lang attribute. It improves accessibility for screen readers and helps search engines and browsers offer correct translations.
Key Takeaways
- <html> is the single root element of every page.
- It contains exactly one <head> and one <body>.
- The lang attribute declares the document language.
- It has no visual output of its own.
- The dir attribute controls left-to-right or right-to-left text.
