Skip to content
Kuza Ndoto Academy

HTML Document Structure

BeginnerChapter 1 · Page 4 of 254 min readUpdated 15 Nov 2026

Every HTML page follows the same basic skeleton: a doctype, then an <html> element containing a <head> and a <body>. Knowing what each part does helps you write pages that display correctly, work on phones and make sense to search engines.

The skeleton

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Nyota Youth SACCO</title>
  </head>
  <body>
    <h1>Nyota Youth SACCO</h1>
    <p>Saving together since 2019.</p>
  </body>
</html>

Let's go through it line by line.

The doctype

<!DOCTYPE html> must be the very first line. It is not an element; it is an instruction telling the browser to use standards mode, meaning it should follow the modern rules for layout. Without it, browsers fall back to quirks mode, which copies the bugs of browsers from the late 1990s so that very old sites still work. In quirks mode some CSS behaves differently, which causes confusing layout problems. The doctype is not case-sensitive, but the uppercase form shown here is the most common.

The html element

<html> is the root element: every other element sits inside it. Always give it a lang attribute with the page's main language:

  • lang="en" for English, lang="sw" for Kiswahili, lang="fr" for French.
  • Screen readers use it to choose the right pronunciation, and browsers use it to offer translation.
  • If one paragraph is in another language, mark just that part: <p lang="sw">Habari za asubuhi!</p>.

The head: information about the page

Content in <head> is not displayed in the page itself. It holds metadata, information about the document, for the browser and other programs:

  • <meta charset="utf-8"> tells the browser the text is encoded as UTF-8, which supports every alphabet plus symbols such as € and emoji. Put it first in the head, because it must appear within the first 1024 bytes of the file.
  • <meta name="viewport" …> makes the page fit phone screens instead of showing a tiny zoomed-out desktop version.
  • <title> sets the text in the browser tab, in bookmarks and as the clickable headline in search results. Every page needs a unique, descriptive title.
  • Other head content includes links to CSS files, icons and scripts. The Head, Meta Tags & SEO page covers these in detail.

The body: what people see

<body> contains everything displayed in the browser window: headings, paragraphs, images, links, forms and so on. A document has exactly one <head> and one <body>.

The document tree

Because elements sit inside other elements, an HTML document forms a family tree. Developers use family words: <html> is the parent of <head> and <body>, which are its children and are siblings of each other. Everything inside an element is its descendants.

html head body meta title h1 p ul li li not displayed shown in the window
Figure 1. The browser turns your HTML into a tree. <head> holds information about the page; <body> holds the visible content.

The browser builds this tree in memory, and it is called the DOM (Document Object Model). CSS uses it to decide what to style and JavaScript uses it to change the page, as you'll see in The DOM Explained.

Indentation and forgiving browsers

Indent child elements by two spaces so the tree is visible in your code. The browser ignores the indentation, but you and your teammates will not.

Browsers are very forgiving. If you leave out <html>, <head> or <body>, the browser quietly adds them to the DOM for you. That is allowed by the standard, but always write them yourself: it makes the structure clear and avoids surprises.

Try the skeleton below. Change the title and the lang value, then add a second paragraph in Kiswahili with its own lang attribute.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Nyota Youth SACCO</title>
  </head>
  <body>
    <h1>Nyota Youth SACCO</h1>
    <p>Saving together since 2019.</p>
    <p lang="sw">Karibu ujiunge nasi!</p>
  </body>
</html>

The preview shows the heading and both paragraphs. The title does not appear on the page itself, because it belongs to the head.

Common mistake

Putting visible content such as an <h1> inside <head>. The browser can't keep it there: it ends the head early and moves the heading into the body, which can push other head elements into the body too. Keep only metadata in the head.

Key points

  • <!DOCTYPE html> comes first and switches the browser to standards mode.
  • <html lang="…"> is the root element and declares the page language.
  • <head> holds metadata (charset, viewport, title); <body> holds the visible content.
  • Nested elements form a tree, the DOM, described with parent, child and sibling.
Up next · Getting StartedElements & AttributesTags, nesting and the attributes that configure elements.
→

Tip: use the ← and → keys to move between pages.