HTML · Chapter 3 of 45

HTML Basic Structure

Every HTML document follows a standard skeleton: a doctype declaration, an <html> root element, a <head> for metadata, and a <body> for visible content.

The doctype tells the browser which HTML version to use. Without it, browsers may render pages in 'quirks mode', causing inconsistent styling.

Syntax
<!DOCTYPE html>
<html>
<head>...</head>
<body>...</body>
</html>

The doctype

<!DOCTYPE html> must be the very first line. It declares the document as HTML5, the current standard.

html, head, body

<html> wraps the whole document. <head> holds metadata like the title and links to stylesheets. <body> contains everything visible to users.

Example 1 (html)
<!DOCTYPE html>
<html lang="en">
<head>
  <title>My Page</title>
</head>
<body>
  <h1>Welcome</h1>
</body>
</html>
Output
Welcome

A complete, valid HTML5 document structure.

Example 2 (html)
<!DOCTYPE html>
<html>
<body>
<p>Minimal but valid</p>
</body>
</html>
Output
Minimal but valid

The head is technically optional, but including a title is best practice.

Key points

  • <!DOCTYPE html> must be the first line.
  • <html> is the root element of the page.
  • <head> holds metadata, not visible content.
  • <body> contains everything the user sees.
💡 Note: The lang attribute on <html> (e.g. lang="en") helps screen readers and search engines.

📝 Quick Quiz

1. What must be the first line of an HTML5 document?

2. Which tag holds visible page content?

3. What does the lang attribute on <html> do?