On this page10 sections
  1. Learning Objectives
  2. 1. The Parts
  3. 2. The HTML
  4. 3. The Complete Page
  5. 4. How the Pieces Work
  6. 5. Common Layout Patterns
  7. Common Beginner Mistakes
  8. Practice Questions
  9. Practice Answers
  10. Key Takeaways

Lecture 032: Website Layout

Category6: CSS in Depth
Lecture032 of 057
Estimated video length14 min
TargetCSS3 · any modern browser
LevelIntermediate

Most websites share one skeleton: a header, a navigation bar, the content (often with a sidebar), and a footer. This lecture builds that whole layout step by step, responsive from phone to desktop.


Learning Objectives

  • Plan a page layout from its parts
  • Build it with semantic HTML and CSS Grid
  • Make it switch from one column on phones to several on desktops
  • Keep the footer at the bottom of short pages

1. The Parts

output
+-------------------------------+
|            header             |
+-------------------------------+
|             nav               |
+--------+----------------------+
|        |                      |
| aside  |        main          |
|        |                      |
+--------+----------------------+
|            footer             |
+-------------------------------+

2. The HTML

html
<header>…</header>
<nav>…</nav>
<div class="layout">
  <aside>…</aside>
  <main>…</main>
</div>
<footer>…</footer>

3. The Complete Page

Example: drag the preview corner from wide to narrow:

html
<style>
  * { box-sizing: border-box; }
  body { margin: 0; font-family: system-ui, sans-serif; color: #212529; min-height: 100vh;
         display: grid; grid-template-rows: auto auto 1fr auto; }

  header { background: #364fc7; color: white; padding: 20px; text-align: center; }
  header h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2.2rem); }

  nav { background: #212529; display: flex; flex-wrap: wrap; }
  nav a { color: #e9ecef; padding: 12px 16px; text-decoration: none; }
  nav a:hover { background: #343a40; }

  .layout { display: grid; gap: 16px; padding: 16px; }
  aside { background: #fff3bf; padding: 14px; border-radius: 8px; }
  main  { background: #f8f9fa; padding: 14px; border-radius: 8px; }
  .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
  .card { background: white; border: 1px solid #dee2e6; border-radius: 8px; padding: 12px; }

  footer { background: #343a40; color: #ced4da; text-align: center; padding: 14px; }

  /* tablets and up: sidebar beside the content */
  @media (min-width: 640px) {
    .layout { grid-template-columns: 200px 1fr; }
  }
</style>

<header><h1>City Bakery</h1></header>
<nav><a href="#">Home</a><a href="#">Menu</a><a href="#">Order</a><a href="#">Contact</a></nav>
<div class="layout">
  <aside><strong>Opening hours</strong><p>Every day, 7am – 10pm.</p></aside>
  <main>
    <h2>Today's specials</h2>
    <div class="cards">
      <div class="card"><strong>Croissant</strong><p>Rs 180</p></div>
      <div class="card"><strong>Banana bread</strong><p>Rs 250</p></div>
      <div class="card"><strong>Cheesecake</strong><p>Rs 450</p></div>
    </div>
  </main>
</div>
<footer>&copy; 2026 City Bakery</footer>

4. How the Pieces Work

  • Sticky footer: body is a grid with rows auto auto 1fr auto. The 1fr row (the content) takes the leftover height, so the footer sits at the bottom even on short pages.
  • Mobile first: .layout is a single column by default; from 640px it becomes 200px 1fr.
  • Cards: repeat(auto-fit, minmax(150px, 1fr)) gives as many columns as fit (Lecture 051).
  • Nav: Flexbox with flex-wrap, so the links wrap on narrow screens.

5. Common Layout Patterns

PatternTypical CSS
Centred content columnmax-width: 1100px; margin-inline: auto; padding-inline: 16px;
Holy grail (sidebar, content, sidebar)grid-template-columns: 200px 1fr 200px;
Full-screen heromin-height: 100vh; display: grid; place-items: center;
Card gridgrid-template-columns: repeat(auto-fit, minmax(250px, 1fr));

Common Beginner Mistakes

1. Building desktop first. Start with one column, then add columns with min-width queries.

2. Fixed pixel widths for the whole page. Use max-width and fractions.

3. A footer floating halfway up short pages. Use the grid-rows trick (or Flexbox with flex: 1 on the content).

4. <div>s everywhere. Use header, nav, main, aside and footer (HTML Lecture 023).


Practice Questions

  1. Name the five common parts of a website layout.
  2. Write the grid columns for a 220px sidebar next to flexible content.
  3. How do you keep the footer at the bottom of a short page using Grid?
  4. Why start with a single-column layout?
  5. Centre the page content with a maximum width of 1000px.

Practice Answers

  1. Header, navigation, main content, sidebar (aside) and footer.
  2. grid-template-columns: 220px 1fr;
  3. Make body a grid with grid-template-rows: auto 1fr auto (or similar) and min-height: 100vh.
  4. Phones get the simplest CSS, and larger screens add to it with min-width media queries.
  5. .container { max-width: 1000px; margin-inline: auto; }

Key Takeaways

  • Header, nav, main, aside and footer make up most layouts.
  • Grid places the big areas; Flexbox handles rows of items such as the nav.
  • Mobile first: one column, then add columns with min-width queries.
  • min-height: 100vh + rows with a 1fr content area keeps the footer down.