Understanding the HTML `<html>` Tag: The Root Element of Every Web Page

Learn about the fundamental role of the `<html>` tag in HTML documents. This tutorial explains its importance as the root container for all other elements, discusses the inclusion of the `lang` attribute for accessibility and SEO, and emphasizes its significance in creating valid and well-structured web pages.



Understanding the HTML `<html>` Tag

The Role of the `<html>` Tag

The <html> tag is the root element of every HTML document. It's the container that encompasses all other elements in your webpage. Everything on your page (including the header section and the content area) is nested within the <html> tag. Think of it as the top-level container or wrapper for the entire page. It is essential for creating a valid HTML document and it is very important for browsers to correctly interpret and render your webpage.

Using the `<html>` Tag

The basic structure using the `<html>` tag is as follows:

Basic HTML Structure

<html>
  <head>
    <title>My Page Title</title>
  </head>
  <body>
    <p>My paragraph.</p>
  </body>
</html>

The <head> section contains meta-information (like the title), and the <body> contains the page's content.

The `lang` Attribute

It's recommended to always include the `lang` attribute within the `<html>` tag to specify the language of your page (e.g., <html lang="en"> for English). This is important for accessibility (screen readers) and SEO (search engine optimization); it signals the language of your content to the browser and search engines.

Browser Support for `<html>`

The `<html>` tag is supported by all web browsers.

Browser Support
Chrome Yes
Edge Yes
Firefox Yes
Opera Yes
Safari Yes

XHTML and the `xmlns` Attribute

If you are creating an XHTML document, you need to specify the XML namespace using the `xmlns` attribute. For example:

XHTML Namespace

<html xmlns="http://www.w3.org/1999/xhtml">

This is not required if you are writing standard HTML5.