Understanding HTML Document Structure
All HTML topicsUnderstanding HTML Document Structure
Every HTML webpage follows a basic structure. Understanding this structure is one of the most important first steps in learning HTML.
Imagine a building. It has a foundation, rooms, doors and different sections.
An HTML document works in a similar way. The document has a main container, a section for page information and a section for visible content.
1ī¸âŖ The Basic HTML Document Structure
A basic HTML document normally looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my webpage.</p>
</body>
</html>2ī¸âŖ See the Structure Clearly
The following tree shows how the main elements are nested inside each other.
3ī¸âŖ What is <!DOCTYPE html>?
The <!DOCTYPE html> declaration
tells the browser that the document is using the
modern HTML standard.
Document declaration
It is placed at the beginning of an HTML document. It helps the browser render the page using standards mode.
4ī¸âŖ What is <html>?
The <html> element is the root
element of an HTML page. Other HTML elements are
placed inside it.
<html lang="en">
...
</html>
The lang="en" attribute indicates that
the primary language of the page is English.
5ī¸âŖ What is <head>?
The <head> contains information
about the webpage. Most of this information is not
displayed directly as page content.
<head>
<meta charset="UTF-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
<title>My Web Page</title>
</head>
6ī¸âŖ Common Elements Inside <head>
<title>
Defines the title shown in the browser tab.
<meta charset="UTF-8">
Defines the character encoding of the document.
<meta name="viewport">
Helps the page display correctly on different
screen sizes.
<link>
Can connect external resources such as CSS files.
7ī¸âŖ What is <title>?
The <title> element defines the
title of the webpage. You normally see it in the
browser tab.
<title>ManaCoding HTML Tutorial</title><title> is
different from an <h1>.
The title belongs to the document information,
while the <h1> is visible page content.
8ī¸âŖ What are <meta> Elements?
Meta elements provide information about the HTML document.
<meta charset="UTF-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>Character encoding
UTF-8 supports a large range of characters and is commonly used for modern webpages.
Responsive display
The viewport setting helps browsers handle the webpage properly on mobile and desktop screens.
9ī¸âŖ What is <body>?
The <body> contains the content
displayed on the webpage.
<body>
<h1>Welcome to ManaCoding</h1>
<p>
Learn HTML step by step.
</p>
<a href="#">
Start Learning
</a>
</body>đ Head vs Body
- Page metadata
- Page title
- Character encoding
- Viewport information
- External resource references
- Headings
- Paragraphs
- Images
- Links
- Forms
- Other visible content
1ī¸âŖ1ī¸âŖ Complete HTML Document Example
Now let's put everything together.
1ī¸âŖ2ī¸âŖ Line-by-Line Understanding
<!DOCTYPE html>
Declares the document as HTML.
<html lang="en">
Starts the root HTML element and declares the
document language.
<head>
Starts the document information section.
<title>
Defines the browser tab title.
<body>
Starts the visible webpage content.
<h1>
Displays the main heading.
<p>
Displays paragraph content.
1ī¸âŖ3ī¸âŖ How the Browser Reads HTML
1ī¸âŖ4ī¸âŖ Understanding HTML Nesting
HTML elements can be placed inside other elements. This is called nesting.
<body>
<div>
<h1>
My Website
</h1>
<p>
Welcome to my website.
</p>
</div>
</body>1ī¸âŖ5ī¸âŖ Common Mistakes
Headings, paragraphs and other visible content
should normally be placed inside
<body>.
Keep the main HTML structure clear: DOCTYPE â html â head â body.
Make sure elements are properly nested and closed when required.
Use consistent indentation so you can easily understand the hierarchy of your HTML.
đ¯ Your Challenge
Create an HTML page containing:
<!DOCTYPE html><html><head>-
A meaningful
<title> <body>-
One
<h1> - Two paragraphs
- One link
đ¤ Interview Questions
What is the root element of an HTML document?
The <html> element is the
root element of an HTML document.
What is the purpose of DOCTYPE?
<!DOCTYPE html> tells the
browser that the document is an HTML document
and helps it use standards mode.
What is the difference between head and body?
The <head> contains document
information and metadata, while the
<body> contains the main
visible content.
Where is the page title defined?
The page title is defined using the
<title> element inside
<head>.
What is HTML nesting?
Nesting means placing one HTML element inside another element to create a structured hierarchy.
⥠Quick Summary
<!DOCTYPE html>declares the HTML document.<html>is the root element.<head>contains document information.<title>defines the browser-tab title.<meta>provides metadata.<body>contains visible webpage content.- HTML elements can be nested to create structure.
- Good indentation makes HTML easier to read.