Document Structure, Metadata, and the Head Section
Every HTML page follows a predictable structure. Learning that structure helps you write pages that browsers, search engines, and assistive technologies can understand correctly.
This chapter explains:
- the overall HTML document shape
- the purpose of
<!DOCTYPE html> - the roles of
<html>,<head>, and<body> - important metadata tags
- why structure matters beyond just making the page render
The Basic Boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Title</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
This boilerplate is the starting point for most HTML documents.
Why Document Structure Matters
Browsers are forgiving, but that does not mean structure is optional.
Good structure helps:
- browsers parse the page correctly
- search engines understand page topics
- screen readers announce the document properly
- developers read and maintain the file
- CSS and JavaScript target elements more predictably
Structure is part of communication. The code is speaking not only to the browser, but also to humans and tools.
<!DOCTYPE html>
Purpose:
- tells the browser to use modern HTML5 parsing rules
Important detail:
- it is not a normal HTML element
- it should be the first line of the file
Without it, browsers may enter a compatibility mode that behaves more like older web standards.
The <html> Element
Purpose:
- wraps the entire document
- acts as the root element
Important attribute:
lang
Common values:
enen-USfrhies
Example:
<html lang="en">
The lang attribute helps:
- screen readers choose pronunciation rules
- search engines understand language
- translation tools behave better
The <head> Section
Purpose:
- stores metadata about the page
- contains information that is usually not shown as page content
Common children:
<title><meta><link><style><script>
The <head> is like the document's information panel. It tells the browser what kind of page this is and what extra resources it needs.
The <body> Section
Purpose:
- contains the visible content users interact with
Common content inside <body>:
- headings
- paragraphs
- navigation
- images
- forms
- media
- tables
- buttons
If users can normally see or interact with it, it usually belongs inside <body>.
A Tree-Like View of the Document
Browsers read HTML as a nested structure often described as the Document Object Model, or DOM.
This Wikimedia diagram shows the idea of a document as a hierarchy of nested objects.
![]()
Source: Wikimedia Commons, "DocumentObjectModelES.svg"
Text description of the image:
- the graphic is arranged like a branching tree
- a document sits near the top
- child elements branch downward below parent elements
- the layout shows that HTML is read as a nested hierarchy, not as random text lines
Even if the labels in a DOM diagram vary, the key lesson is the same:
- parent elements contain child elements
- structure affects meaning and behavior
- order and nesting matter
Important Head Elements
<title>
Purpose:
- sets the browser tab title
- helps search engines understand the page topic
- appears in bookmarks and shared links
Example:
<title>HTML5 Course Overview</title>
Good title habits:
- make each page title unique
- keep it relevant to the page content
- avoid vague titles like
Homewhen a more descriptive title is possible
<meta>
Purpose:
- describes metadata such as character encoding, author info, description, viewport settings, and browser instructions
Important attributes:
charsetnamecontenthttp-equiv
Common examples:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Learn HTML5 step by step.">
<meta name="author" content="Nandhoo">
charset
Purpose:
- defines the character encoding for the document
Most modern pages should use:
<meta charset="UTF-8">
UTF-8 supports many characters and languages.
viewport
Purpose:
- helps responsive pages display correctly on phones and tablets
Common example:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
description
Purpose:
- provides a short summary of the page
This can help search engines and previews understand the page.
<link>
Purpose:
- connects the document to external resources such as stylesheets, icons, and related files
Common attributes:
relhrefmediasizestype
Example:
<link rel="stylesheet" href="styles.css">
Other common uses:
<link rel="icon" href="favicon.ico">
<style> and <script> in the Head
<style>
Purpose:
- contains CSS rules directly inside the document
Example:
<style>
body { font-family: sans-serif; }
</style>
<script>
Purpose:
- loads or contains JavaScript
Example:
<script src="app.js" defer></script>
The defer attribute is often helpful because it allows the document to be parsed before the script runs.
Common Structure Patterns in the Body
Many pages use a semantic structure like this:
<body>
<header>
<h1>Site Title</h1>
</header>
<nav>
<a href="/">Home</a>
</nav>
<main>
<article>
<h2>Page Topic</h2>
<p>Page content goes here.</p>
</article>
</main>
<footer>
<p>© 2026</p>
</footer>
</body>
That structure makes the page easier to understand for both users and tools.
Metadata Best Practices
- always include
charset="UTF-8" - always include a viewport meta tag for responsive pages
- give every page a unique title
- write a meaningful meta description for important pages
- set the correct
langvalue on<html> - keep the
<head>focused on document information, not visible content
Common Mistakes
- placing visible content inside
<head> - forgetting the
<title> - skipping
lang - omitting the doctype
- using too many unnecessary meta tags
- giving every page the same title
- confusing
<head>with a visible page header
Beginner Mental Model
Think of the document like this:
<!DOCTYPE html>says what rules to use<html>wraps the whole document<head>explains the document<body>shows the document
That simple mental model makes a lot of HTML structure easier to remember.