HTML Document Structure: Doctype, Head and Body
A complete HTML page has a small set of outer elements that tell browsers what kind of document they are reading, what information describes the page, and where the visible content belongs.
Quick answer: start with <!doctype html>, wrap the page in <html lang="en">, put document information inside <head>, and place visible page content inside <body>.
The main parts of an HTML document
<!doctype html>tells the browser to use modern standards mode.<html>is the root element around the document. Itslangattribute identifies the primary language.<head>contains document metadata, the title, and links to resources such as stylesheets.<body>contains the content people read and interact with.
Use a complete starter document
This minimal example includes common metadata for an English-language page. Change the language code when the page’s primary language is different.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My page title</title>
<meta name="description" content="A short summary of this page.">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>A clear page heading</h1>
</header>
<main>
<p>Visible page content goes here.</p>
</main>
</body>
</html>
What belongs in the head?
The <head> is for information about the document rather than the page’s main visible content. A useful starting set includes a character encoding declaration, viewport settings, a meaningful title, and links to stylesheets. A meta description can summarize the page, although search engines may choose a different snippet for a query.
Why set the language on the html element?
The lang attribute identifies the main language of the page. Assistive technology can use it to choose pronunciation rules, and browsers can use it for language-aware features. Use the language that matches most of the page content, such as lang="en" for English or another appropriate language tag for a different language.
What goes inside the body?
Put visible page content inside <body>. For a typical page, use a site <header>, navigation, one <main> region for the page’s central content, and a <footer> when those regions are needed. Use headings and semantic elements that describe the meaning of the content.
Common document-structure mistakes
- Leaving out the doctype or typing it after page content.
- Putting visible headings and paragraphs in the head instead of the body.
- Leaving the primary language off the html element or using a language that does not match the content.
- Using a generic browser-tab title instead of a title that describes the page.
- Forgetting viewport metadata, which can make a page render at an unexpected width on mobile devices.
Continue learning HTML
Start with your first web page, then learn how elements and tags work. See the lessons on page titles, semantic HTML, and connecting HTML and CSS.
For a detailed reference, read MDN’s guide to basic HTML syntax and its reference for the head element.