Aral Code

Page Structure Lesson 27 of 42

HTML Page Layout — Building a Complete Page

Combine semantic HTML and a little CSS Flexbox to build a real page layout with a header, navigation, content area, sidebar and footer.

You now know enough elements to build a complete web page. In this lesson we'll put them together into a classic layout — header on top, navigation menu, main content with a sidebar, and a footer — and use a little CSS to arrange them. This is the same structure used by school websites, blogs and small business pages everywhere.

Step 1: plan the layout

Before typing code, sketch the page on paper. Most websites follow this pattern:

┌─────────────────────────────────┐
│            HEADER               │
├─────────────────────────────────┤
│            NAV                  │
├──────────────────────┬──────────┤
│                      │          │
│        MAIN          │  ASIDE   │
│                      │          │
├──────────────────────┴──────────┤
│            FOOTER               │
└─────────────────────────────────┘

Each box becomes one semantic element.

Step 2: write the HTML structure

First, just the HTML — no styling. Content first, design second.

Example Structure only
<header>
  <h1>Kusina ni Lola</h1>
  <p>Home-cooked Filipino recipes</p>
</header>
<nav>
  <a href="#">Home</a>
  <a href="#">Recipes</a>
  <a href="#">About</a>
</nav>
<div class="container">
  <main>
    <h2>Chicken Tinola</h2>
    <p>A comforting ginger soup with chicken, green papaya and malunggay leaves. Perfect for rainy days.</p>
    <p>Prep time: 15 minutes · Cooking time: 40 minutes</p>
  </main>
  <aside>
    <h3>Popular Recipes</h3>
    <ul>
      <li>Sinigang na Baboy</li>
      <li>Pancit Canton</li>
      <li>Leche Flan</li>
    </ul>
  </aside>
</div>
<footer>
  <p>&copy; 2026 Kusina ni Lola</p>
</footer>

It's readable but plain — everything is stacked. The <div class="container"> around main and aside is a layout helper: we need it so we can put those two side by side.

Step 3: add CSS with Flexbox

Flexbox is a CSS tool for arranging boxes in a row or column. Setting display: flex on a container places its children side by side. Here's the full page with styles:

Example The finished layout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kusina ni Lola</title>
<style>
  body { margin: 0; font-family: Arial, sans-serif; color: #2b2b2b; }
  header { background: #b4372b; color: white; padding: 20px; text-align: center; }
  header h1 { margin: 0; }
  header p { margin: 4px 0 0; }
  nav { background: #2b2b2b; display: flex; justify-content: center; gap: 4px; }
  nav a { color: white; text-decoration: none; padding: 12px 16px; }
  nav a:hover { background: #555; }
  .container { display: flex; gap: 20px; padding: 20px; }
  main { flex: 3; }
  aside { flex: 1; background: #fdf3dc; padding: 12px 16px; border-radius: 8px; }
  footer { background: #eee; text-align: center; padding: 12px; font-size: 14px; }

  /* On narrow screens, stack main and aside */
  @media (max-width: 600px) {
    .container { flex-direction: column; }
  }
</style>
</head>
<body>
<header>
  <h1>Kusina ni Lola</h1>
  <p>Home-cooked Filipino recipes</p>
</header>
<nav>
  <a href="#">Home</a>
  <a href="#">Recipes</a>
  <a href="#">About</a>
</nav>
<div class="container">
  <main>
    <h2>Chicken Tinola</h2>
    <p>A comforting ginger soup with chicken, green papaya and malunggay leaves. Perfect for rainy days.</p>
    <p>Prep time: 15 minutes · Cooking time: 40 minutes</p>
  </main>
  <aside>
    <h3>Popular Recipes</h3>
    <ul>
      <li>Sinigang na Baboy</li>
      <li>Pancit Canton</li>
      <li>Leche Flan</li>
    </ul>
  </aside>
</div>
<footer>
  <p>&copy; 2026 Kusina ni Lola</p>
</footer>
</body>
</html>

What the key CSS lines do

  • body { margin: 0; } removes the browser's default space around the page so the header touches the edges.
  • nav { display: flex; justify-content: center; } puts the links in a row, centered.
  • .container { display: flex; gap: 20px; } puts <main> and <aside> side by side with a 20px gap.
  • main { flex: 3; } and aside { flex: 1; } split the width 3 to 1 — the main part gets three times more space.
  • The @media (max-width: 600px) part is a media query: on narrow screens (phones), the main content and sidebar stack on top of each other instead.

Other layout tools

Flexbox is great for one direction (a row or a column). For two-dimensional layouts — rows and columns, like a photo gallery — CSS has Grid. A taste:

Example A photo gallery with CSS Grid
<style>
  .gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .gallery img { width: 100%; height: auto; border-radius: 6px; background: #eee; }
</style>
<div class="gallery">
  <img src="/img/mango.svg" alt="Mango">
  <img src="/img/jeepney.svg" alt="Jeepney">
  <img src="/img/halo-halo.svg" alt="Halo-halo">
  <img src="/img/jeepney.svg" alt="Jeepney">
  <img src="/img/mango.svg" alt="Mango">
  <img src="/img/school-logo.svg" alt="School logo">
</div>

You'll study Flexbox and Grid properly in the CSS course. For now, the goal is to see how good HTML structure makes layout easy.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. What does display: flex on a container do by default?
2. With main { flex: 3; } and aside { flex: 1; }, how is the space divided?
3. What is the purpose of @media (max-width: 600px)?
4. What should you do first when building a layout?

By Sir Reyel · Last updated 2026-12-04