The
<html>tag represents the root element of an HTML document.
All other HTML elements — such as<head>,<body>,<div>,<p>, etc. — must be nested inside the<html>element.
It defines the start and end of an HTML document and can include alangattribute to specify the language of the content.
Syntax
<html lang="en">
<!-- All other HTML content goes here -->
</html>lang="en"sets the language to English (recommended for accessibility and SEO).- Must enclose both
<head>and<body>tags.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Root Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This content is inside the <html> root element.</p>
</body>
</html>Output
Browser Output:
Displays “Welcome to My Website” as a heading and the paragraph below it.
Browser Support:
Chrome | Firefox | Edge | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
All content on the page is contained within the <html> element, though this container is not visibly shown in the browser.
Notes
- Always use
<html>as the first element after<!DOCTYPE>. - Including the
langattribute improves accessibility for screen readers and helps search engines understand your content. - Closing tag
</html>is mandatory in HTML5. - Other global attributes (like
dir="ltr"for text direction) can also be added.
Conclusion
The <html> tag is the foundation of every HTML document, acting as a container for all content.
Using it properly ensures your page is structured correctly, accessible, and compatible with browsers and search engines.
Always pair it with <!DOCTYPE html> at the very top of your document for full HTML5 compliance.