In this section of our HTML tutorial, we will explore the <html>
element, a fundamental component of every HTML document. We will examine its role, attributes, and provide code examples to help you understand how it functions.
Understanding the <html>
Element
The <html>
element serves as the root element of every HTML document. It encapsulates the entire content of a web page. All other HTML elements, such as headings, paragraphs, links, and images, are contained within the <html>
element.
Basic Syntax
Here is the basic syntax of the <html>
element:
1 2 3 4 |
<!DOCTYPE html> <!-- Document Type Declaration (DOCTYPE) --> <html> <!-- Content of the HTML document goes here --> </html> |
<!DOCTYPE html>
: This declaration specifies the HTML version (HTML5) that the document adheres to.<html>
: The opening tag of the<html>
element.</html>
: The closing tag of the<html>
element, which marks the end of the document.
Attributes
The <html>
element can also include attributes. The most commonly used attribute is the lang
attribute, which specifies the language of the document. This can be helpful for screen readers and search engines. Here’s an example:
1 2 3 4 |
<!DOCTYPE html> <html lang="en"> <!-- Content of the HTML document in English --> </html> |
In the example above, lang="en"
indicates that the document is in English.
Code Examples
Let’s look at a simple HTML document that uses the <html>
element:
1 2 3 4 5 6 7 8 9 10 |
<!DOCTYPE html> <html> <head> <title>My First HTML Page</title> </head> <body> <h1>Welcome to My Web Page</h1> <p>This is a sample HTML document.</p> </body> </html> |
In this example, the <html>
element encapsulates the entire HTML document, with the content contained within the <body>
element.
Conclusion
The <html>
element is the foundational element of an HTML document, encapsulating the entire content of a web page. Understanding its role and proper usage is essential for creating well-structured web pages. As you continue with this tutorial, you’ll explore more HTML elements, attributes, and techniques to build rich and interactive web pages.