If you’re just starting your web development journey, understanding the structure of an HTML document is a crucial first step. HTML (Hypertext Markup Language) forms the backbone of every webpage on the internet. In this guide, we’ll break down a simple HTML document line by line to help you understand how it works and why each part is important.
Here’s the HTML document we’ll be working with:
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
Now, let’s dive into what each part of this code does.
Line 1: Declaring the Document Type
- This line tells the browser that the document is written in HTML5.
- Why it’s important: Without the
<!DOCTYPE>
declaration, browsers might display the webpage using older rendering methods, leading to inconsistencies.
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
Think of it as a way of saying, “This is a modern HTML document.”
Lines 2 and 10: Opening and closing the root element
- The
<html>
element wraps all the content of your webpage. - Everything between
<html>
and</html>
is part of your webpage
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
It’s like the outer wrapper that holds all the pieces of your webpage together.
Lines 3 and 5: Metadata and Behind-the-Scenes Information
- The
<head>
section contains information about the page that isn’t displayed on the screen. - Key contents of the
<head>
include:<title>
: Sets the title that appears in the browser tab.- Links to stylesheets, scripts, and other resources.
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
Line 4: Browser tab title
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
The text within the <title>
tag will appear on the browser tab title. Example below:

Lines 5 and 9: The visible content
- The
<body>
element contains all the content that will appear on the webpage. - Anything visible to users—text, images, buttons—goes inside the
<body>
.
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
Line 7: The main heading
<h1>
is the top-level heading tag and is usually used for the main title of a page.
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
This will display “Welcome to My Website” as a large heading at the top of the page.
Line 8: Paragraphs of text
- The
<p>
tag is used to define paragraphs.
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first webpage created with HTML!</p>
</body>
</html>
How This Example Comes Together
- A title in the browser tab: “My First Webpage.”
- A large heading: “Welcome to My Website.”
- A paragraph of text: “This is my first webpage created with HTML!”
When you put all of these parts together and open the file in a browser, here’s what you’ll see:

Experiment With the Code
Try modifying the code to see what happens:
- Change the Heading: Replace “Welcome to My Website” with your own text.
- Add More Paragraphs: Copy and paste the
<p>
tag to add more text. - Use Other Tags: Add new elements like
<ul>
for lists or<img>
for images.
Conclusion
Understanding the basic structure of an HTML document is the foundation for building webpages. Once you’re comfortable with this, you can start exploring more HTML elements and combining them with CSS and JavaScript to create amazing websites.
Want to learn more about HTML? Check out the HTML Basics Guide to get started!