Cyber Code Academy
Tutorials Academy Courses
Home / html-tutorials-md / HTML Document Structure

HTML Document Structure

> Understand the doctype, root element, document head, body, metadata, and correct nesting.

**Cyber Code Academy · HTML Tutorial · Lesson 03 · Beginner**

## 1. Why document structure matters

An HTML document is not just a collection of tags. It has a defined structure that helps browsers, search engines, assistive technologies, and developers understand the page.

A correctly structured page:
– Declares the document type.
– Identifies the language of the content.
– Includes useful metadata.
– Provides a meaningful browser title.
– Separates document metadata from visible page content.
– Uses a logical hierarchy of elements.

## 2. The complete HTML skeleton

“`html

HTML Document Structure

Welcome to HTML

Introduction

This is the main content of the page.

Copyright 2026 Cyber Code Academy

“`

This is a useful starting point for many simple web pages.

## 3. The doctype declaration

`` is a declaration, not a normal HTML element. It tells the browser to use the modern standards mode for HTML documents.

Write it at the very beginning of the document. The declaration is not displayed as page content.

## 4. The html root element

“ is the root element. All other HTML elements are descendants of it.

The `lang` attribute identifies the primary language:

“`html

“`

For a Hindi-language document, use an appropriate language tag such as `hi`. Correct language metadata supports pronunciation and language processing by assistive technologies and other software.

## 5. The head element

The “ element contains metadata and resource references. It is not the place for normal page paragraphs, headings, or images that should appear in the visible content.

Common children include:
– `title`
– `meta`
– `link`
– `style`
– `script`
– `base`

### Title
“`html
HTML Tutorial for Beginners | Cyber Code Academy
“`
The title identifies the page in browser tabs, bookmarks, and often search result displays. Make it descriptive and specific.

### Character encoding
“`html

“`
UTF-8 supports the characters used by many languages and symbols. Place the declaration near the beginning of the head.

### Viewport
“`html

“`
This tells mobile browsers to use the device width as the layout viewport. It is important for responsive pages.

### Description
“`html

“`
A description summarizes the page. Search engines may use it for snippets, but they can choose other text.

## 6. The body element

The “ contains the document’s visible content and interactive interface. It may include headings, paragraphs, images, navigation, forms, tables, and semantic sections.

A document has one body element. Put page content inside it, not in the head.

## 7. Correct nesting and indentation

HTML elements can contain other elements. The nesting order must be valid:

“`html

About HTML

HTML structures web content.


“`

Do not cross closing tags. Incorrect nesting can make the browser repair the markup in a way you did not intend.

## 8. HTML comments in a document

“`html

My Page


“`

Comments are visible in page source. Never put passwords, API keys, or private information in them.

## 9. Expected document tree

The browser creates a DOM tree with relationships similar to this:

“`text
document
└── html
├── head
│ ├── meta
│ ├── title
│ └── meta
└── body
├── header
│ └── h1
├── main
│ ├── h2
│ └── p
└── footer
└── p
“`

## 10. Common mistakes

– Omitting the doctype.
– Putting a page heading inside head.
– Forgetting the title.
– Setting the wrong document language.
– Using duplicate root, head, or body structures.
– Writing malformed nested elements.
– Forgetting viewport metadata and then wondering why a mobile page is scaled strangely.

## 11. Practice exercises

1. Create a complete HTML skeleton from memory.
2. Add a title, description, character encoding, and viewport.
3. Create header, main, and footer areas.
4. Set the language to Hindi for a Hindi sample page.
5. Inspect the DOM tree in your browser.

## 12. Knowledge check

1. What does the doctype declaration do?
2. What is the root element?
3. What kind of information belongs in head?
4. What kind of content belongs in body?
5. Why is the lang attribute important?
6. What is the purpose of the viewport meta element?

**Next lesson:** HTML Tags, Elements, and Attributes.

Want to learn this professionally?

Explore practical IT training at Cyber Code Academy.

View Academy Courses