EthicsComputerCourses
Join training +91 90532 10052

Advanced HTML5 Architecture

HTML · Lesson 41 of 234 Intermediate 9 min read Updated

By the end of this lesson you will be able to plan a whole page before you type a single tag. You will sketch it as a tree of landmarks and components, check that each element is allowed where you put it, and separate the parts that repeat on every page from the parts that change.

In Level 1 you learnt the skeleton of a page in HTML Document Structure and the meaning of each region in Semantic HTML5 Elements. This lesson is about the step before both: architecture.

Plan first, type later

A builder in Pune does not start with bricks. An architect first draws a plan. Changing a line on paper costs nothing; moving a wall later costs a lot.

HTML works the same way. A page is a tree: one root, with branches inside branches. Plan the tree first and the tags almost write themselves. Start typing instead, and you often end up with <div> inside <div> inside <div>.

Professional teams plan in three layers:

LayerQuestion it answersExample
TemplateWhat repeats on every page?Site header, main menu, footer
LandmarksWhat are the big regions of this page?Main content, sidebar, search
ComponentsWhich small units repeat inside regions?Story card, author box, share buttons

Templates and page content

The page template is the shell that every page shares. The page content is what makes one page different from another.

Think of a daily newspaper. The masthead and the printer's line on the last page look the same every morning; the stories change. On a website, the header, navigation and footer are the masthead, and <main> holds each day's stories.

The template is usually written once and reused by a server-side language or a framework (see HTML with PHP & MySQL). If the template is right, each new page only needs its own <main>.

Content models: what may go inside what

Every element in the HTML standard has a content model: a rule that says what it is allowed to contain. To make the rules shorter, the standard groups elements into content categories. The most useful ones are:

CategoryPlain meaningExamples
MetadataInformation about the page, kept in the head<title>, <meta>, <link>
FlowAlmost anything that can sit in the body<p>, <div>, <ul>, <table>
PhrasingText and the small elements that sit inside a line<a>, <strong>, <span>, <img>
HeadingHeadings<h1> to <h6>, <hgroup>
SectioningRegions that may have their own heading and footer<article>, <section>, <nav>, <aside>
InteractiveThings the user can click or type into<a href>, <button>, <input>

A few rules cause most real bugs:

  • <p> may contain phrasing content only. A <div>, a list or a table inside a paragraph is not allowed.
  • <button> and <a> must not contain other interactive content, so no link inside a button.
  • <ul> and <ol> may contain only <li> elements (plus script elements).
  • <a> is transparent: it takes the content model of its parent. Inside a <div>, a link may wrap a whole card, headings included.

The browser does not show an error when you break these rules. It quietly repairs the tree, and the repaired tree is not the one you planned. Run this to watch it happen.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Content model repair</title>
</head>
<body>
  <section id="demo">
    <p>Today's weather in Jaipur <div>32°C and sunny</div> with light wind.</p>
  </section>

  <h2>The tree the browser actually built</h2>
  <pre id="out"></pre>

  <script>
    const html = document.querySelector("#demo").innerHTML;
    document.querySelector("#out").textContent = html;
  </script>
</body>
</html>

The output shows <p>Today's weather in Jaipur </p><div>32°C and sunny</div> with light wind.<p></p>. The browser closed the paragraph at the <div> and turned the stray </p> into a new empty paragraph. You will study these repair rules properly in HTML Content Categories and Phrasing vs Flow Content.

Sectioning and headings

Sectioning elements (<article>, <section>, <nav>, <aside>) split a page into parts that each have a topic. Two facts guide your plan:

  • Heading levels are yours to choose. Older tutorials taught an "outline algorithm" where every section could start with <h1>. Browsers never built it, and it was removed from the standard in 2022. Choose levels by nesting: page title <h1>, main parts <h2>, parts inside them <h3>.
  • Some elements become landmarks that screen reader users can jump between. <main>, <nav> and <aside> always count. A <header> or <footer> counts only when it belongs to the whole page. A <section> counts only when it has an accessible name, such as aria-labelledby pointing at its heading. The full story is in HTML Document Outline & Landmarks.

Live coding: planning a news site

Let us plan the home page of Pune Pratidin, a made-up city news site.

Step 1: list the page's jobs in plain words. Show the site name and a search box. Show the top story big, then more stories. Put "most read" and a live cricket score on the side. End with contact links.

Step 2: turn the jobs into a tree. Write it as indented text. No tags yet, just names and the element you plan to use.

Text
body
├── header (template: logo, search, menu)
│   ├── search
│   └── nav "Main menu"
├── main (page content)
│   ├── article.lead       top story, h2
│   └── section "More stories", h2
│       └── article.card × 6, h3 each
├── aside (complementary)
│   ├── section "Most read", h2
│   └── section "Live score", h2
└── footer (template: contact, legal links)

The header and footer are template branches; <main> changes on every page.

Step 3: name the components. The story card appears six times on the home page, and also on category pages and search results. Design it once:

HTML
<article class="card">
  <a href="/city/metro-line-3">
    <img src="metro.jpg" alt="Metro coach being tested on the elevated track at Shivajinagar" width="400" height="250">
    <h3>Metro Line 3 trial run begins next week</h3>
  </a>
  <p>Commuters between Hinjewadi and Shivajinagar can expect services by March.</p>
  <footer>
    <time datetime="2026-11-15T08:30+05:30">15 Nov, 8:30 am</time>
  </footer>
</article>

The link may wrap the image and heading because <a> is transparent and <article> accepts flow content. The card's small <footer> is not a page landmark, because it sits inside an article.

Step 4: write the skeleton. Only now do you type the page. The CSS outlines every region and prints its tag name.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en-IN">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Pune Pratidin | City news</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 8px; }
    header, nav, search, main, article, section, aside, footer {
      border: 1px dashed #999; margin: 6px 0; padding: 18px 8px 6px; position: relative;
    }
    [data-tag]::before {
      content: attr(data-tag); position: absolute; top: 0; left: 4px;
      font-size: 11px; color: #b33;
    }
    h1, h2, h3 { margin: 4px 0; }
  </style>
</head>
<body>
  <header data-tag="header">
    <h1>Pune Pratidin</h1>
    <search data-tag="search">
      <form action="#"><label>Search news <input type="search" name="q"></label></form>
    </search>
    <nav data-tag="nav" aria-label="Main menu">
      <a href="#">City</a> | <a href="#">Sports</a> | <a href="#">Business</a>
    </nav>
  </header>

  <main data-tag="main">
    <article data-tag="article (lead)">
      <h2>PMC approves new cycle tracks on FC Road</h2>
      <p>The 2.4 km track will open before the monsoon.</p>
    </article>
    <section data-tag="section" aria-labelledby="more">
      <h2 id="more">More stories</h2>
      <article data-tag="article (card)"><h3>Metro Line 3 trial run begins</h3></article>
      <article data-tag="article (card)"><h3>Water cut in Kothrud on Tuesday</h3></article>
    </section>
  </main>

  <aside data-tag="aside">
    <section data-tag="section" aria-labelledby="read"><h2 id="read">Most read</h2></section>
    <section data-tag="section" aria-labelledby="score"><h2 id="score">Live score</h2><p>Maharashtra 212/4 (38 ov)</p></section>
  </aside>

  <footer data-tag="footer"><p>Pune Pratidin, Shivajinagar, Pune</p></footer>
</body>
</html>

Compare the result with the tree from Step 2. Every branch has a home, heading levels follow the nesting, and the sidebar sits outside <main>.

Common mistakes

  • Typing before planning. The result is deep <div> nesting with no meaning. Draw the tree first.
  • Block elements inside <p>. The parser splits your paragraph. Use a <div> as the outer box instead.
  • Putting the sidebar inside <main>. Content that repeats across pages, such as "Most read", belongs in an <aside> outside <main>.

Interview questions

1. What is a content model in HTML?

It is the rule in the HTML standard that says what an element may contain. For example, <p> may contain only phrasing content, and <ul> only <li> elements. Breaking it shows no error; the parser repairs the tree its own way.

2. What happens if you put a <div> inside a <p>?

The parser closes the paragraph when it meets the <div>, because a paragraph cannot hold flow content. The rest of the sentence ends up outside, and the closing </p> creates an extra empty paragraph. The DOM no longer matches the source code.

3. What is the difference between a page template and page content?

The template is the shared shell that every page repeats: header, navigation and footer. The page content is unique to one page and normally lives in <main>. Separating them lets a team write the shell once and reuse it.

4. Should every <section> start with an <h1>?

No. The outline algorithm that would have adjusted those levels was never implemented by browsers and was removed from the standard. Use heading levels that match the nesting of the content.

Key points

  • Plan a page as a tree in three layers: template, landmarks and components.
  • The template repeats on every page; <main> holds the content unique to one page.
  • Every element has a content model; <p> takes phrasing content only, and interactive elements cannot nest.
  • The browser silently repairs invalid nesting, so the DOM can differ from your source.
  • Choose heading levels by nesting; the old outline algorithm no longer exists.

Exercise

Plan the article page of Pune Pratidin, which opens when a reader clicks a story card. First write an indented text tree and mark the template branches. The page needs the shared header and footer, the story (headline, author, time, two subheadings), three "Related stories" cards and a "Most read" sidebar. Then write the matching HTML skeleton.

Show solution
Text
body
├── header (template)
├── main
│   ├── article (story), h1 headline
│   │   ├── header: author, time
│   │   ├── section, h2 × 2
│   │   └── footer: tags
│   └── section "Related stories", h2
│       └── article.card × 3, h3
├── aside: section "Most read", h2
└── footer (template)
HTML
<body>
  <header><!-- template: logo, search, menu --></header>
  <main>
    <article>
      <header>
        <h1>PMC approves new cycle tracks on FC Road</h1>
        <p>By Ananya Kulkarni, <time datetime="2026-11-15T07:45+05:30">15 Nov 2026</time></p>
      </header>
      <section><h2>Where the tracks will run</h2><p>...</p></section>
      <section><h2>What cyclists say</h2><p>...</p></section>
      <footer><p>Tags: civic, cycling</p></footer>
    </article>
    <section aria-labelledby="related">
      <h2 id="related">Related stories</h2>
      <article class="card"><h3>New bus stops on JM Road</h3></article>
      <article class="card"><h3>Parking rules change in Deccan</h3></article>
      <article class="card"><h3>Smart signals at 20 junctions</h3></article>
    </section>
  </main>
  <aside aria-labelledby="most-read">
    <section><h2 id="most-read">Most read</h2></section>
  </aside>
  <footer><!-- template: contact, legal links --></footer>
</body>

Here the story headline is the <h1>, because it is this page's main topic. The sidebar stays outside <main>.

Quick Quiz

1. Which content may a <p> element contain?

2. Where should a "Most read" list that appears on every article page usually go?

3. When does a <footer> become the page's contentinfo landmark?

4. Why can an <a> element wrap a whole card with a heading inside an <article>?

Learn HTML with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call