DOCTYPE, html, head, and body explained
Your roadmap for this lesson
- What <!DOCTYPE html> does and why it is first
- The <html> root element and the lang attribute
- What belongs inside <head>
- What belongs inside <body>
Short answer
<!DOCTYPE html> tells the browser to use modern standards mode. <html> is the root element that wraps everything, and its lang attribute names the page language. <head> holds metadata the browser and search engines read. <body> holds the content people see.
<!DOCTYPE html>
The doctype declaration is always the very first line. It is not a tag. It is an instruction that says: this is a modern HTML document.
Without it, browsers fall back to quirks mode, an old way of rendering built for websites from the 1990s. Layouts can break in strange ways. With it, browsers use standards mode.
<html lang=“en”>
The <html> element is the root element. Every other element lives inside it.
The lang attribute tells browsers, screen readers, and translation tools which language the page uses.
| Page language | lang value |
|---|---|
| English | en |
| English (Philippines) | en-PH |
| Filipino | fil |
| Tagalog | tl |
A screen reader uses lang to pick the right pronunciation. Google Translate uses it to decide when to offer a translation.
<head>
The head holds information about the document:
<meta charset="utf-8">: the character encoding, so letters like ñ and ₱ display correctly.<meta name="viewport">: makes the page fit phone screens.<title>: the text in the browser tab and Google results.<link>: connects CSS files and favicons.<script>: loads JavaScript.
<body>
Everything a visitor can see or click goes in the body: headings, paragraphs, images, links, tables, forms, and videos. You will spend most of this course inside the body.
Try it: set the language and encoding
This page has a missing charset and the wrong language. Add a meta charset line in the head and change lang to fil, since the text is Filipino.
Live preview
Quick quiz
Common mistakes
- Putting the doctype second. It must be the first line, before any spaces or comments ideally.
- Skipping lang. Screen readers may read your page with the wrong accent.
- Placing charset late. Put the charset meta tag first inside head so the browser reads it early.
Your action
Tick each item when you can do it. Your progress saves on this device.
Key terms
- Doctype declaration
- The first line, <!DOCTYPE html>, that turns on standards mode.
- Quirks mode
- An old rendering mode browsers use when the doctype is missing.
- Root element
- The <html> element that contains all others.
- lang attribute
- Declares the language of the page or an element.
- Character encoding
- How text is stored as bytes. UTF-8 is the standard.
- Metadata
- Data about the page, stored in the head.
Questions beginners ask
Is DOCTYPE case sensitive?
No. <!doctype html> works too. Many people write it in uppercase by habit.
Can one page mix languages?
Yes. Set the main lang on <html>, then add lang="fil" on any paragraph in Filipino.
Why UTF-8?
UTF-8 covers nearly every language and symbol, including the peso sign. It is the web standard.
Related lessons
Need a website built or fixed while you practice? The team at Remar Digital can help.