KodingKaro
HTML · Beginner · HTML Document Structure

The doctype and root html element

A predictable document shell helps browsers interpret your page consistently and gives assistive technology the language context it needs.

✓ What you will learn in this topic

  • Explain the purpose of The doctype and root html element in a real HTML document.
  • Choose and apply the elements shown in both examples.
  • Recognize the specific mistake described in this lesson.

Concept explanation

The doctype declaration tells the browser to use modern HTML parsing; it is not an element. The html element is the document root. Its lang attribute names the primary language of the page, for example en or fr. This setting helps screen readers choose pronunciation rules and helps translation and indexing tools understand the content.

Syntax

Place the doctype first, then wrap the document in one html element with a suitable lang value.

Example 1: a small page

The doctype comes before the root. The language code describes the main language used in the page.

<!doctype html>
<html lang=\"en\">
  <body><p>Hello!</p></body>
</html>

Expected result: A page displays the word Hello! and the browser parses it in modern HTML mode.

Example 2: a practical page

A region-specific language tag can be appropriate when the content follows that locale’s language conventions.

<!doctype html>
<html lang=\"en-CA\">
  <head><title>Toronto Trail Club</title></head>
  <body><h1>Trail Club</h1></body>
</html>

Expected result: The page displays Trail Club, while the document language is exposed to browser tools.

Common mistakes

Visible page content belongs in body; metadata such as the title and character encoding belongs in head.

Best practices

Use the HTML doctype, set the document language, declare UTF-8, include the mobile viewport, and write a useful title.

Practice exercise

Create a complete HTML file for a local book club. Give it a language, a descriptive browser-tab title, and one visible heading and paragraph.

Lesson summary

  • Use a doctype and one root html element; identify the content language accurately.
  • Use the HTML doctype, set the document language, declare UTF-8, include the mobile viewport, and write a useful title.

Knowledge check

Where should the primary document language be declared?

Show the explanation

Set lang on the root html element so the language applies to the complete document unless a passage needs its own language.

Practical example

html
<!doctype html>
<html lang=\"en\">
  <body><p>Hello!</p></body>
</html>

Expected result:

A page displays the word Hello! and the browser parses it in modern HTML mode.

Hands-on practice task

Create a complete HTML file for a local book club. Give it a language, a descriptive browser-tab title, and one visible heading and paragraph.

In this section

Other lessons in HTML Document Structure

Broaden your knowledge

Related learning topics