HTML <html>
Tag
The <html>
tag is the root element of an HTML document. It signifies the beginning and end of an HTML page, encompassing all other HTML elements. Every HTML document must have this tag as its outermost container. It essentially tells the browser that the content within it is HTML and how to process it.
Syntax
<html lang="language-code" manifest="URL">
<!-- HTML document content -->
</html>
Attributes
Attribute | Value | Description |
---|---|---|
lang |
language_code (e.g., en , es , fr , de , etc.) |
Specifies the language of the content within the HTML document. Helps screen readers and search engines. |
manifest |
URL |
Specifies the location of the document's application cache manifest, enabling offline functionality in web apps. This is deprecated in HTML5. |
xmlns |
URL |
Specifies the XML namespace for the document. Primarily used with XHTML documents, not common in HTML5. |
Example
<html lang="en">
<head>
<title>My Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a basic HTML document.</p>
</body>
</html>
More Examples
Example 1: Specifying Language
Setting the language helps browsers and assistive technologies understand the content, which enhances accessibility and SEO.
<html lang="es">
<head>
<title>Mi Página Web</title>
</head>
<body>
<h1>Bienvenido a mi sitio web</h1>
<p>Este es un documento HTML básico.</p>
</body>
</html>
Example 2: A More Complete HTML Structure
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Complex Webpage</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>Main Content</h2>
<p>This is where the main content of the page resides.</p>
</section>
<aside>
<h3>Sidebar</h3>
<p>Related content or ads can go here.</p>
</aside>
</main>
<footer>
<p>© 2024 My Website</p>
</footer>
<script src="script.js"></script>
</body>
</html>
Browser Support
The <html>
tag is supported by all major browsers and has been a fundamental part of HTML since its inception:
Browser | Version |
---|---|
Chrome | All |
Edge | All |
Firefox | All |
Safari | All |
Opera | All |
Notes and Tips
- Mandatory: The
<html>
tag is mandatory for all HTML documents. Omitting it will lead to the document not being properly parsed or rendered by web browsers. - Single instance: There should be only one
<html>
tag in an HTML document. It's the root element that everything else sits within. - Language Attribute: Always include the
lang
attribute. This improves accessibility and helps with search engine optimization (SEO). Use the appropriate language code for the primary language of the document. - Structure: The
<html>
tag acts as the container for the<head>
and<body>
elements and all their children. - No Content Direct: No text or other content should be placed directly within the
<html>
tag outside the<head>
or<body>
tags. Always structure your page with proper child elements. - Deprecated Attribute: The
manifest
andxmlns
attributes are generally not used in modern HTML5 practices but included here for completeness. The application cache and XML namespaces aren't primary concerns for regular websites these days.