<html>
The <html>
tag is the root of an HTML document. It encapsulates all visible and invisible content of a webpage, defining the beginning and end of an HTML document. It is essential for browsers to properly interpret HTML code.
It does not fully encapsulate the entire page since it must be placed after the
<!DOCTYPE html>
declaration.
Structure of the HTML Tag
The <html>
tag is a container tag (meaning it encloses other elements). It consists of two parts:
- The opening tag:
<html>
- The closing tag:
</html>
Thus, it is a tag that works in pairs.
Syntax
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example HTML Page</title>
</head>
<body>
<p>Long live Believemy!</p>
</body>
</html>
As you can see, it is very important to add the lang
attribute to your <html>
tags.
This attribute allows you to specify the language of the page content, which is helpful for search engines, for instance.
This ensures that your page is correctly indexed by search engines! 😉
Attributes
lang
As mentioned above, the lang
attribute specifies the language of the content on a page. It is critical for accessibility and search engines.
This
lang
attribute is what allows browsers to display popups offering to translate a page! 😋
xmlns
The xmlns
attribute (for XML Namespace) specifies the XML namespace used in the HTML document.
It is primarily required in XHTML documents to indicate that the content adheres to XML specification rules.
The default namespace is always http://www.w3.org/1999/xhtml.
Here’s a quick example:
<html xmlns="http://www.w3.org/1999/xhtml">
...
</html>
However, with the advent of HTML5, this attribute is no longer mandatory.
class / id
It is entirely possible to customize the CSS style of a page using the class
and id
attributes.
Compatibility
The <html>
tag is compatible with all browsers.
Element | Google Chrome | Safari | Mozilla Firefox | Edge |
<html> | Yes | Yes | Yes | Yes |