Logo OnlineCBT
HTML Tutorial
HTML · LESSON 5

HTML Document Structure

Understand the boilerplate structure of every HTML document including doctype, html, head, and body tags.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive
Updated: 30 Jul 2026

HTML Document Structure

1. The Document Object Model (DOM) Tree Architecture

When a web browser downloads an HTML document from a server, it does not simply render plain text line by line. Instead, the browser's HTML parser transforms the raw markup into a structured hierarchical memory model called the Document Object Model (DOM) Tree.

Understanding this tree hierarchy is essential for mastering layout design, CSS targeting, and JavaScript manipulation.

DOM Relationships Explained

  • Root Node: The <html> element is the ultimate top-level parent node of the entire document tree.
  • Parent Nodes: An element that directly encloses other elements. For example, <body> is the parent of <main> or <h1>.
  • Child Nodes: Elements positioned directly inside a parent element. For example, <li> nodes are children of a <ul> parent.
  • Sibling Nodes: Elements that share the exact same parent node on the same hierarchical level (e.g., two paragraphs inside the same <article>).
<!-- DOM Tree Representation -->
<html>                           <!-- Root Node -->
  <head></head>                 <!-- Child of html, Sibling of body -->
  <body>                       <!-- Child of html, Parent of main -->
    <main>                     <!-- Child of .tech-lesson-content, Parent of h1 and p -->
      <h1>Heading</h1>         <!-- Child of main, Sibling of p -->
      <p>Paragraph text.</p>   <!-- Child of main, Sibling of h1 -->
    </main>
  </body>
</html>
Why DOM Architecture Matters:

Malformed HTML (like unclosed tags or invalid tag nesting) breaks the browser's DOM parsing engine. When the DOM tree breaks, CSS styling fails, layout shifts occur, and JavaScript event listeners cannot locate targets correctly.

2. Block-Level vs. Inline Elements

Every HTML element has a default display behavior defined by the browser's user-agent stylesheet. HTML elements fall primarily into two fundamental display categories: Block-Level Elements and Inline Elements.

Feature / Property Block-Level Elements Inline Elements
Default Line Behavior Always starts on a fresh new line. Forces subsequent elements down. Sits gracefully in-line alongside surrounding text or elements without breaking lines.
Width Behavior Expands horizontally to fill 100% of available parent width by default. Takes up only as much width as its enclosed content requires.
Height & Width Customization Accepts explicit CSS width and height properties. Ignores explicit CSS width and height properties.
Margin & Padding Respects top, bottom, left, and right margins and padding completely. Respects horizontal (left/right) margin/padding, but ignores vertical (top/bottom) margins.
Common Element Examples <div>, <p>, <h1>-<h6>, <ul>, <li>, <article>, <header> <span>, <a>, <strong>, <em>, <code>, <img>

Code Example: Block vs. Inline Behavior

<!-- Block Elements (Stack Vertically) -->
<p style="background: #e2e8f0;">I am a Block element (Paragraph 1).</p>
<p style="background: #cbd5e1;">I am a Block element (Paragraph 2).</p>

<!-- Inline Elements (Sit Side-by-Side) -->
<span style="background: #fef08a;">Inline Item 1</span>
<span style="background: #bbf7d0;">Inline Item 2</span>
<span style="background: #bfdbfe;">Inline Item 3</span>
Hardcoded Output Result (Display Difference)

I am a Block element (Paragraph 1).

I am a Block element (Paragraph 2).

Inline Item 1 Inline Item 2 Inline Item 3

3. Generic Containers: The <div> and <span> Elements

When no specific semantic element applies, HTML provides two generic container elements used exclusively for grouping content for CSS styling or JavaScript interaction.

1. The <div> (Document Division) Element

A <div> is a non-semantic block-level container. It carries no inherent structural meaning or SEO value. It is used to group large sections of HTML together to apply layout styling (like CSS Flexbox or CSS Grid) or CSS background colors.

2. The <span> Element

A <span> is a non-semantic inline container. It is used to isolate specific words, phrases, or characters inside a block element to apply target text styling (such as changing color, font weight, or background highlight) without breaking the sentence flow.

<!-- Combining div and span -->
<div style="background: #f1f5f9; padding: 15px; border-radius: 6px;">
    <h3 style="margin-top: 0;">Container Title</h3>
    <p>This paragraph lives inside a div container, but this <span style="color: #2563eb; font-weight: bold;">blue highlighted phrase</span> is isolated inside a span.</p>
</div>
Hardcoded Output Result (Grouping)

Container Title

This paragraph lives inside a div container, but this blue highlighted phrase is isolated inside a span.

Avoid "Div Soup":

Overusing nested <div> elements everywhere instead of proper semantic tags (like <header>, <article>, <footer>) creates unmaintainable code known as "Div Soup", which hurts page accessibility and SEO performance.

4. Modern Semantic Page Segmentation Architecture

Modern HTML5 documents divide full web pages into clear, logical, and standardized structural regions using semantic sectioning elements.

<!-- Complete Semantic Page Architecture -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Semantic Web Architecture</title>
</head>
<body>

    <!-- Top Site Header -->
    <header>
        <h1>Tech Journal</h1>
        <nav>
            <a href="#home">Home</a> | <a href="#articles">Articles</a>
        </nav>
    </header>

    <!-- Main Viewport Content -->
    <main>
        <article>
            <h2>Understanding Semantic Web</h2>
            <p>Articles represent standalone, reusable content items.</p>
        </article>

        <aside>
            <h3>Related Posts</h3>
            <p>Sidebar links and supplementary info.</p>
        </aside>
    </main>

    <!-- Global Footer -->
    <footer>
        <p>&copy; 2026 Tech Journal. All rights reserved.</p>
    </footer>

</body>
</html>
Hardcoded Output Result (Semantic Structure)

Tech Journal

Understanding Semantic Web

Articles represent standalone, reusable content items.

© 2026 Tech Journal. All rights reserved.

Semantic Region Breakdown

  • <header>: Defines global introductory branding, site titles, or primary navigation wrappers.
  • <nav>: Reserved specifically for primary site navigation link lists.
  • <main>: Represents the unique, primary content core of the document. Must appear only once per page.
  • <article>: Self-contained content blocks intended for independent distribution (e.g., blog posts, news stories, forum comments).
  • <section>: Logical thematic groupings of content, usually containing an explicit heading.
  • <aside>: Indirectly related content such as sidebars, advertising blocks, author bios, or related link groups.
  • <footer>: Contains copyright notices, privacy policy links, sitemaps, and author contact details.

5. Homework Assignments & Practical Exercises

Task 1: Semantic Refactoring (Current Lesson)

Create an index.html file representing a mini news site. Build a complete layout using <header>, <nav>, <main> containing two <article> nodes, an <aside> sidebar, and a <footer>. Ensure zero non-semantic <div> tags are used for sectioning.

Task 2: Block vs. Inline Experimentation (Current Lesson)

Write an HTML file containing three paragraphs. Inside the second paragraph, use three separate <span> tags to highlight individual words with different inline CSS background colors. Add a <div> container wrapping paragraphs 2 and 3, and explain how the container manages their layout.

Task 3: Comprehensive DOM Architecture Revision (All-Inclusive Task)

Combine knowledge from Lessons 01 through 05: Construct a complete valid HTML5 page, open it in Chrome DevTools, expand the DOM tree in the Elements Panel, identify the parent-child-sibling relationships between <main>, <article>, and <p>, and validate your code through validator.w3.org.

6. Frequently Asked Interview Questions

Q1: What is the main difference between an <article> and a <section> in HTML5?

Answer: An <article> is a completely self-contained piece of content that makes logical sense on its own if syndicated or shared independently (e.g., a news article, blog post, or product card). A <section> is a thematic grouping of related content within a larger page, typically requiring an accompanying heading (e.g., "Features Section", "Contact Section").

Q2: Why can't inline elements wrap block-level elements in standard HTML?

Answer: By specification, inline elements (like <span> or <em>) are designed to live inside text streams and cannot contain structural block-level containers (like <div> or <p>). Nesting a block element inside an inline element breaks line layout rendering. (Note: HTML5 explicitly allows anchor tags <a> to wrap entire block elements for hyperlinking purposes).

Q3: What is the Document Object Model (DOM), and how does it relate to HTML source code?

Answer: HTML source code is plain text written by developers. The DOM is an in-memory object tree generated by the browser parser after reading that raw HTML text. JavaScript manipulates the DOM in memory to dynamically update elements, styles, and content without needing to edit the raw HTML file stored on disk.

Q4: Why should a web page contain only one <main> tag?

Answer: The <main> element highlights the core, non-repeating content unique to that specific URL. Including multiple <main> elements creates ambiguity for accessibility software (screen readers use <main> as a primary landmark to skip navigation menus) and violates HTML5 validation rules.

Lesson 06 Preview: HTML Elements, Tags and Attributes

Now that you master structural page segmentation and DOM tree architecture, our next lesson explores individual element construction in deep detail:

  • Deep Dive into Element Anatomy: Void elements vs. Container elements and self-closing mechanics.
  • Mastering HTML Attributes: Global attributes (id, class, style, title, data-*) vs. element-specific attributes.
  • Case Sensitivity & Quotation Best Practices: Writing clean, bug-free production attributes.
  • Boolean Attributes: Understanding how attributes like disabled, required, and checked behave.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat