HTML REFERENCE · 01
Document Structure
An HTML document has two main parts: head contains information about the page, and body contains the page content. Both belong inside the html element.
The parts of an HTML document
| Code | What it means | When and where to use it |
|---|---|---|
<!DOCTYPE html>
|
A declaration that tells the browser to use modern standards mode. It is not an element and does not display anything. | Put it first in every new HTML document, before the opening html tag. It has no closing tag. |
<html>
|
The root element: the outer container holding the document's head and body. | Open it after the doctype. Close it after body. Everything in head and body belongs inside it. |
lang="en"
|
An attribute declaring that the content is English. Tools such as screen readers can use it to choose pronunciation rules. | Add it to the opening html tag for an English page. It declares the language; it does not translate text. |
<head>
|
A container for information about the document, including its title, metadata, and resource references. | Put it inside html, before body. Put page settings here rather than your visible introduction. |
<meta charset="UTF-8">
|
Declares the character encoding: how the browser interprets the file's bytes as text. UTF-8 supports many writing systems and symbols. | Put it near the beginning of head and save the file as UTF-8. Meta is a void element, so it has no closing tag. |
<meta name="viewport" …>
|
Configures the mobile layout viewport. The setting below uses the device width and an initial scale of 1. | Include it in head when starting a page. It supports mobile layouts, but CSS is still needed to make the design adapt well. |
<title>
|
Names the document in the browser tab and supplies its default bookmark title. It does not create a heading in the page. | Put one descriptive title inside head. For example, “About Nikki | My Website.” |
<link rel="stylesheet" …>
|
Connects an external CSS file. Rel identifies it as a stylesheet; href gives its location. | Put it in head when styling is stored separately. For this lesson, ../css/styles.css goes up one folder, then into css. |
<body>
|
Contains the document's page content: the text, images, links, and controls visitors use. | Put it after head, inside html. Your visible page content goes between its opening and closing tags. |
Remember: head describes the page. Body contains the page content. Head is different from a visible heading.
Full document example
Notice how head and body sit inside html. Indentation makes these relationships easier to read.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>Nikki's Profile</title>
</head>
<body>
<h1>Hi, I'm Nikki!</h1>
<p>I am learning HTML.</p>
</body>
</html>
What the visitor sees
Browser tab: Nikki's Profile
Hi, I'm Nikki!
I am learning HTML.
The example tab label above is an illustration. This lesson's actual browser tab uses the title at the top of this file.
How the parts fit together
Html is the parent of head and body. Head and body are siblings because they share that parent. Title is a child of head.
Close an inner element before closing its container. Meta and link are exceptions to the opening-and-closing pattern: they are void elements and have no closing tags.
Study questions
Think of your answer, then click to reveal it.
Why does the document start with a doctype?
It tells the browser to use standards mode. Without an appropriate doctype, the browser may use older compatibility behavior called quirks mode.
What belongs inside html?
The document's head and body. Html is the outer root element containing both. The doctype declaration goes before it.
How are head and body different?
Head contains document information and resource references. Body contains the page content visitors read and interact with.
Does lang="en" translate the page?
No. It declares English as the language. The actual words remain whatever you wrote.
What is a character encoding?
A system for interpreting stored bytes as characters. Declaring UTF-8 and saving the file as UTF-8 helps the browser display the intended text.
Does viewport meta make any page responsive?
No. It configures the mobile viewport. Flexible CSS layouts and suitably sized content are still needed.
Where does title appear?
In the browser tab, rather than as a heading in the page content. Changing title does not automatically change the page's visible heading.
Which elements here have no closing tag?
Meta and link are void elements with no closing tags. The doctype also has no closing tag because it is a declaration, not an element.
What does ../css/styles.css mean?
From this HTML file's folder, go up one folder, enter css, and find styles.css.
Does indentation control nesting?
No. Tags determine the structure. Indentation helps people see that structure.